Initial refactoring
This commit is contained in:
parent
c7bbb80213
commit
8c4ac76b98
7 changed files with 206 additions and 145 deletions
|
@ -941,6 +941,7 @@ public class SettingsHelper {
|
||||||
JSONObject object = itemsJson.getJSONObject(i);
|
JSONObject object = itemsJson.getJSONObject(i);
|
||||||
String name = object.getString("name");
|
String name = object.getString("name");
|
||||||
int actionType = object.getInt("type");
|
int actionType = object.getInt("type");
|
||||||
|
// TODO
|
||||||
String paramsString = object.getString("params");
|
String paramsString = object.getString("params");
|
||||||
HashMap<String, String> params = gson.fromJson(paramsString, type);
|
HashMap<String, String> params = gson.fromJson(paramsString, type);
|
||||||
QuickAction quickAction = new QuickAction(actionType);
|
QuickAction quickAction = new QuickAction(actionType);
|
||||||
|
|
|
@ -86,7 +86,7 @@ public class AddQuickActionDialog extends DialogFragment {
|
||||||
private static final int HEADER = 1;
|
private static final int HEADER = 1;
|
||||||
private static final int ITEM = 2;
|
private static final int ITEM = 2;
|
||||||
|
|
||||||
private List<QuickAction> data;
|
private List<QuickActionType> data;
|
||||||
|
|
||||||
public class ItemViewHolder extends RecyclerView.ViewHolder {
|
public class ItemViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ public class AddQuickActionDialog extends DialogFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Adapter(List<QuickAction> data) {
|
public Adapter(List<QuickActionType> data) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ public class AddQuickActionDialog extends DialogFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||||
|
|
||||||
final QuickAction action = data.get(position);
|
final QuickActionType action = data.get(position);
|
||||||
|
|
||||||
if (getItemViewType(position) == HEADER) {
|
if (getItemViewType(position) == HEADER) {
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ public class AddQuickActionDialog extends DialogFragment {
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
|
|
||||||
if (data.get(position).type == 0)
|
if (data.get(position).getId() == 0)
|
||||||
return HEADER;
|
return HEADER;
|
||||||
|
|
||||||
return ITEM;
|
return ITEM;
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.quickaction;
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
@ -26,52 +27,38 @@ public class QuickAction {
|
||||||
protected int type;
|
protected int type;
|
||||||
protected long id;
|
protected long id;
|
||||||
|
|
||||||
private @StringRes Integer nameRes;
|
|
||||||
private @DrawableRes int iconRes;
|
|
||||||
private boolean isActionEditable;
|
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private HashMap<String, String> params;
|
private HashMap<String, String> params;
|
||||||
|
private QuickActionType actionType;
|
||||||
|
|
||||||
protected QuickAction() {
|
protected QuickAction() {
|
||||||
this.id = System.currentTimeMillis();
|
this.id = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected QuickAction(int type, @StringRes int nameRes) {
|
public QuickAction(QuickActionType type) {
|
||||||
|
// FIXME id
|
||||||
this.id = System.currentTimeMillis();
|
this.id = System.currentTimeMillis();
|
||||||
this.nameRes = nameRes;
|
this.actionType = type;
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public QuickAction(int type) {
|
|
||||||
this.id = System.currentTimeMillis();
|
|
||||||
this.type = type;
|
|
||||||
this.nameRes = QuickActionFactory.getActionName(type);
|
|
||||||
this.iconRes = QuickActionFactory.getActionIcon(type);
|
|
||||||
this.isActionEditable = QuickActionFactory.isActionEditable(type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public QuickAction(QuickAction quickAction) {
|
public QuickAction(QuickAction quickAction) {
|
||||||
this.type = quickAction.type;
|
this.type = quickAction.type;
|
||||||
|
this.actionType = quickAction.actionType;
|
||||||
this.id = quickAction.id;
|
this.id = quickAction.id;
|
||||||
this.name = quickAction.name;
|
this.name = quickAction.name;
|
||||||
this.params = quickAction.params;
|
this.params = quickAction.params;
|
||||||
|
|
||||||
this.nameRes = QuickActionFactory.getActionName(type);
|
|
||||||
this.iconRes = QuickActionFactory.getActionIcon(type);
|
|
||||||
this.isActionEditable = QuickActionFactory.isActionEditable(type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNameRes() {
|
public int getNameRes() {
|
||||||
return nameRes;
|
return actionType == null ? 0 : actionType.getNameRes();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getIconRes() {
|
public int getIconRes() {
|
||||||
return iconRes;
|
return actionType == null ? 0 : actionType.getIconRes();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getIconRes(Context context) {
|
public int getIconRes(Context context) {
|
||||||
return iconRes;
|
return actionType == null ? 0 : actionType.getIconRes();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getId() {
|
public long getId() {
|
||||||
|
@ -83,7 +70,7 @@ public class QuickAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActionEditable() {
|
public boolean isActionEditable() {
|
||||||
return isActionEditable;
|
return actionType == null ? false : actionType.isActionEditable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActionEnable(OsmandApplication app) {
|
public boolean isActionEnable(OsmandApplication app) {
|
||||||
|
@ -92,13 +79,18 @@ public class QuickAction {
|
||||||
|
|
||||||
public String getName(Context context) {
|
public String getName(Context context) {
|
||||||
if (Algorithms.isEmpty(name)) {
|
if (Algorithms.isEmpty(name)) {
|
||||||
return nameRes != null ? context.getString(nameRes) : "";
|
return getDefaultName(context);
|
||||||
} else {
|
} else {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, String> getParams() {
|
@NonNull
|
||||||
|
private String getDefaultName(Context context) {
|
||||||
|
return getNameRes() != 0 ? context.getString(getNameRes()) : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, String> getParams() {
|
||||||
|
|
||||||
if (params == null) params = new HashMap<>();
|
if (params == null) params = new HashMap<>();
|
||||||
|
|
||||||
|
@ -121,7 +113,11 @@ public class QuickAction {
|
||||||
return getName(application);
|
return getName(application);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAutoGeneratedTitle(EditText title){
|
public QuickActionType getActionType() {
|
||||||
|
return actionType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAutoGeneratedTitle(EditText title){
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute(MapActivity activity){};
|
public void execute(MapActivity activity){};
|
||||||
|
@ -158,13 +154,10 @@ public class QuickAction {
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = type;
|
int result = type;
|
||||||
result = 31 * result + (int) (id ^ (id >>> 32));
|
result = 31 * result + (int) (id ^ (id >>> 32));
|
||||||
result = 31 * result + nameRes;
|
|
||||||
result = 31 * result + iconRes;
|
|
||||||
result = 31 * result + (name != null ? name.hashCode() : 0);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasCustomName(Context context) {
|
public boolean hasCustomName(Context context) {
|
||||||
return !getName(context).equals(context.getString(nameRes));
|
return !getName(context).equals(context.getString(getDefaultName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ import net.osmand.plus.quickaction.actions.ShowHideOSMBugAction;
|
||||||
import net.osmand.plus.quickaction.actions.ShowHidePoiAction;
|
import net.osmand.plus.quickaction.actions.ShowHidePoiAction;
|
||||||
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
||||||
import net.osmand.plus.srtmplugin.SRTMPlugin;
|
import net.osmand.plus.srtmplugin.SRTMPlugin;
|
||||||
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -49,6 +50,13 @@ import java.util.List;
|
||||||
|
|
||||||
public class QuickActionFactory {
|
public class QuickActionFactory {
|
||||||
|
|
||||||
|
public static final QuickActionType TYPE_ADD_ITEMS = new QuickActionType(0, "").
|
||||||
|
nameRes(R.string.quick_action_add_create_items).category(QuickActionType.CREATE_CATEGORY);
|
||||||
|
public static final QuickActionType TYPE_CONFIGURE_MAP = new QuickActionType(0, "").
|
||||||
|
nameRes(R.string.quick_action_add_configure_map).category(QuickActionType.CONFIGURE_MAP);
|
||||||
|
public static final QuickActionType TYPE_NAVIGATION = new QuickActionType(0, "").
|
||||||
|
nameRes(R.string.quick_action_add_navigation).category(QuickActionType.NAVIGATION);
|
||||||
|
)
|
||||||
public String quickActionListToString(List<QuickAction> quickActions) {
|
public String quickActionListToString(List<QuickAction> quickActions) {
|
||||||
return new Gson().toJson(quickActions);
|
return new Gson().toJson(quickActions);
|
||||||
}
|
}
|
||||||
|
@ -60,125 +68,99 @@ public class QuickActionFactory {
|
||||||
return quickActions != null ? quickActions : new ArrayList<QuickAction>();
|
return quickActions != null ? quickActions : new ArrayList<QuickAction>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<QuickAction> produceTypeActionsListWithHeaders(List<QuickAction> active) {
|
|
||||||
ArrayList<QuickAction> quickActions = new ArrayList<>();
|
|
||||||
quickActions.add(new QuickAction(0, R.string.quick_action_add_create_items));
|
|
||||||
quickActions.add(new FavoriteAction());
|
|
||||||
quickActions.add(new GPXAction());
|
|
||||||
QuickAction marker = new MarkerAction();
|
|
||||||
|
|
||||||
if (!marker.hasInstanceInList(active)) {
|
public static List<QuickActionType> getActionTypes() {
|
||||||
quickActions.add(marker);
|
List<QuickActionType> quickActionsTypes = new ArrayList<>();
|
||||||
}
|
quickActionsTypes.add(FavoriteAction.TYPE);
|
||||||
|
quickActionsTypes.add(GPXAction.TYPE);
|
||||||
|
quickActionsTypes.add(MarkerAction.TYPE);
|
||||||
|
|
||||||
|
// FIXME plugins
|
||||||
|
|
||||||
if (OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class) != null) {
|
if (OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class) != null) {
|
||||||
QuickAction audio = new TakeAudioNoteAction();
|
quickActionsTypes.add(TakeAudioNoteAction.TYPE);
|
||||||
QuickAction photo = new TakePhotoNoteAction();
|
quickActionsTypes.add(TakePhotoNoteAction.TYPE);
|
||||||
QuickAction video = new TakeVideoNoteAction();
|
quickActionsTypes.add(TakeVideoNoteAction.TYPE);
|
||||||
|
|
||||||
if (!audio.hasInstanceInList(active)) {
|
|
||||||
quickActions.add(audio);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!photo.hasInstanceInList(active)) {
|
|
||||||
quickActions.add(photo);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!video.hasInstanceInList(active)) {
|
|
||||||
quickActions.add(video);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null) {
|
if (OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null) {
|
||||||
quickActions.add(new AddPOIAction());
|
quickActionsTypes.add(AddPOIAction.TYPE);
|
||||||
quickActions.add(new AddOSMBugAction());
|
quickActionsTypes.add(AddOSMBugAction.TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OsmandPlugin.getEnabledPlugin(ParkingPositionPlugin.class) != null) {
|
if (OsmandPlugin.getEnabledPlugin(ParkingPositionPlugin.class) != null) {
|
||||||
QuickAction parking = new ParkingAction();
|
quickActionsTypes.add(ParkingAction.TYPE);
|
||||||
if (!parking.hasInstanceInList(active)) {
|
|
||||||
quickActions.add(parking);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// configure map
|
||||||
|
quickActionsTypes.add(ShowHideFavoritesAction.TYPE);
|
||||||
|
quickActionsTypes.add(ShowHideGpxTracksAction.TYPE);
|
||||||
|
quickActionsTypes.add(ShowHidePoiAction.TYPE);
|
||||||
|
|
||||||
quickActions.add(new QuickAction(0, R.string.quick_action_add_configure_map));
|
|
||||||
|
|
||||||
QuickAction favorites = new ShowHideFavoritesAction();
|
|
||||||
if (!favorites.hasInstanceInList(active)) {
|
|
||||||
quickActions.add(favorites);
|
|
||||||
}
|
|
||||||
|
|
||||||
quickActions.add(new ShowHideGpxTracksAction());
|
|
||||||
|
|
||||||
quickActions.add(new ShowHidePoiAction());
|
|
||||||
if (OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null) {
|
if (OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null) {
|
||||||
QuickAction showHideOSMBugAction = new ShowHideOSMBugAction();
|
quickActionsTypes.add(ShowHideOSMBugAction.TYPE);
|
||||||
if (!showHideOSMBugAction.hasInstanceInList(active)) {
|
|
||||||
quickActions.add(showHideOSMBugAction);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
quickActions.add(new MapStyleAction());
|
quickActionsTypes.add(MapStyleAction.TYPE);
|
||||||
if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) != null) {
|
if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) != null) {
|
||||||
quickActions.add(new MapSourceAction());
|
quickActionsTypes.add(MapSourceAction.TYPE);
|
||||||
quickActions.add(new MapOverlayAction());
|
quickActionsTypes.add(MapOverlayAction.TYPE);
|
||||||
quickActions.add(new MapUnderlayAction());
|
quickActionsTypes.add(MapUnderlayAction.TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null) {
|
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null) {
|
||||||
quickActions.add(new ContourLinesAction());
|
quickActionsTypes.add(ContourLinesAction.TYPE);
|
||||||
quickActions.add(new HillshadeAction());
|
quickActionsTypes.add(HillshadeAction.TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
quickActions.add(new DayNightModeAction());
|
quickActionsTypes.add(DayNightModeAction.TYPE);
|
||||||
|
|
||||||
|
// navigation
|
||||||
|
quickActionsTypes.add(NavVoiceAction.TYPE);
|
||||||
|
quickActionsTypes.add(NavDirectionsFromAction.TYPE);
|
||||||
|
quickActionsTypes.add(NavAddDestinationAction.TYPE);
|
||||||
|
quickActionsTypes.add(NavAddFirstIntermediateAction.TYPE);
|
||||||
|
quickActionsTypes.add(NavReplaceDestinationAction.TYPE);
|
||||||
|
quickActionsTypes.add(NavAutoZoomMapAction.TYPE);
|
||||||
|
quickActionsTypes.add(NavStartStopAction.TYPE);
|
||||||
|
quickActionsTypes.add(NavResumePauseAction.TYPE);
|
||||||
|
return quickActionsTypes;
|
||||||
|
}
|
||||||
|
|
||||||
QuickAction voice = new NavVoiceAction();
|
public static List<QuickActionType> produceTypeActionsListWithHeaders(List<QuickAction> active) {
|
||||||
QuickAction directionFrom = new NavDirectionsFromAction();
|
List<QuickActionType> quickActions = new ArrayList<>();
|
||||||
QuickAction addDestination = new NavAddDestinationAction();
|
List<QuickActionType> tps = getActionTypes();
|
||||||
QuickAction addFirstIntermediate = new NavAddFirstIntermediateAction();
|
filterQuickActions(active, tps, TYPE_ADD_ITEMS, quickActions);
|
||||||
QuickAction replaceDestination = new NavReplaceDestinationAction();
|
filterQuickActions(active, tps, TYPE_CONFIGURE_MAP, quickActions);
|
||||||
QuickAction autoZoomMap = new NavAutoZoomMapAction();
|
filterQuickActions(active, tps, TYPE_NAVIGATION, quickActions);
|
||||||
QuickAction startStopNavigation = new NavStartStopAction();
|
|
||||||
QuickAction resumePauseNavigation = new NavResumePauseAction();
|
|
||||||
|
|
||||||
ArrayList<QuickAction> navigationQuickActions = new ArrayList<>();
|
|
||||||
|
|
||||||
if (!voice.hasInstanceInList(active)) {
|
|
||||||
navigationQuickActions.add(voice);
|
|
||||||
}
|
|
||||||
if (!directionFrom.hasInstanceInList(active)) {
|
|
||||||
navigationQuickActions.add(directionFrom);
|
|
||||||
}
|
|
||||||
if (!addDestination.hasInstanceInList(active)) {
|
|
||||||
navigationQuickActions.add(addDestination);
|
|
||||||
}
|
|
||||||
if (!addFirstIntermediate.hasInstanceInList(active)) {
|
|
||||||
navigationQuickActions.add(addFirstIntermediate);
|
|
||||||
}
|
|
||||||
if (!replaceDestination.hasInstanceInList(active)) {
|
|
||||||
navigationQuickActions.add(replaceDestination);
|
|
||||||
}
|
|
||||||
if (!autoZoomMap.hasInstanceInList(active)) {
|
|
||||||
navigationQuickActions.add(autoZoomMap);
|
|
||||||
}
|
|
||||||
if (!startStopNavigation.hasInstanceInList(active)) {
|
|
||||||
navigationQuickActions.add(startStopNavigation);
|
|
||||||
}
|
|
||||||
if (!resumePauseNavigation.hasInstanceInList(active)) {
|
|
||||||
navigationQuickActions.add(resumePauseNavigation);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (navigationQuickActions.size() > 0) {
|
|
||||||
quickActions.add(new QuickAction(0, R.string.quick_action_add_navigation));
|
|
||||||
quickActions.addAll(navigationQuickActions);
|
|
||||||
}
|
|
||||||
|
|
||||||
return quickActions;
|
return quickActions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static QuickAction newActionByType(int type) {
|
private static void filterQuickActions(List<QuickAction> active, List<QuickActionType> allTypes, QuickActionType filter,
|
||||||
|
List<QuickActionType> result) {
|
||||||
|
result.add(filter);
|
||||||
|
for(QuickActionType t : allTypes) {
|
||||||
|
if(t.getCategory() == filter.getCategory()) {
|
||||||
|
if(t.isActionEditable()) {
|
||||||
|
boolean instanceInList = false;
|
||||||
|
for(QuickAction qa : active) {
|
||||||
|
if(qa.getActionType().getId() == t.getId()) {
|
||||||
|
instanceInList = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!instanceInList) {
|
||||||
|
result.add(t);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result.add(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static QuickAction newActionByType(int type) {
|
||||||
|
// FIXME
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
||||||
case NewAction.TYPE:
|
case NewAction.TYPE:
|
||||||
|
@ -217,9 +199,6 @@ public class QuickActionFactory {
|
||||||
case ShowHideOSMBugAction.TYPE:
|
case ShowHideOSMBugAction.TYPE:
|
||||||
return new ShowHideOSMBugAction();
|
return new ShowHideOSMBugAction();
|
||||||
|
|
||||||
case AddOSMBugAction.TYPE:
|
|
||||||
return new AddOSMBugAction();
|
|
||||||
|
|
||||||
case AddPOIAction.TYPE:
|
case AddPOIAction.TYPE:
|
||||||
return new AddPOIAction();
|
return new AddPOIAction();
|
||||||
|
|
||||||
|
@ -274,7 +253,7 @@ public class QuickActionFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static QuickAction produceAction(QuickAction quickAction) {
|
public static QuickAction produceAction(QuickAction quickAction) {
|
||||||
|
// FIXME
|
||||||
switch (quickAction.type) {
|
switch (quickAction.type) {
|
||||||
|
|
||||||
case NewAction.TYPE:
|
case NewAction.TYPE:
|
||||||
|
@ -313,9 +292,6 @@ public class QuickActionFactory {
|
||||||
case ShowHideOSMBugAction.TYPE:
|
case ShowHideOSMBugAction.TYPE:
|
||||||
return new ShowHideOSMBugAction(quickAction);
|
return new ShowHideOSMBugAction(quickAction);
|
||||||
|
|
||||||
case AddOSMBugAction.TYPE:
|
|
||||||
return new AddOSMBugAction(quickAction);
|
|
||||||
|
|
||||||
case AddPOIAction.TYPE:
|
case AddPOIAction.TYPE:
|
||||||
return new AddPOIAction(quickAction);
|
return new AddPOIAction(quickAction);
|
||||||
|
|
||||||
|
@ -409,9 +385,6 @@ public class QuickActionFactory {
|
||||||
case ShowHideOSMBugAction.TYPE:
|
case ShowHideOSMBugAction.TYPE:
|
||||||
return R.drawable.ic_action_bug_dark;
|
return R.drawable.ic_action_bug_dark;
|
||||||
|
|
||||||
case AddOSMBugAction.TYPE:
|
|
||||||
return R.drawable.ic_action_bug_dark;
|
|
||||||
|
|
||||||
case AddPOIAction.TYPE:
|
case AddPOIAction.TYPE:
|
||||||
return R.drawable.ic_action_gabout_dark;
|
return R.drawable.ic_action_gabout_dark;
|
||||||
|
|
||||||
|
@ -505,9 +478,6 @@ public class QuickActionFactory {
|
||||||
case ShowHideOSMBugAction.TYPE:
|
case ShowHideOSMBugAction.TYPE:
|
||||||
return R.string.quick_action_showhide_osmbugs_title;
|
return R.string.quick_action_showhide_osmbugs_title;
|
||||||
|
|
||||||
case AddOSMBugAction.TYPE:
|
|
||||||
return R.string.quick_action_add_osm_bug;
|
|
||||||
|
|
||||||
case AddPOIAction.TYPE:
|
case AddPOIAction.TYPE:
|
||||||
return R.string.quick_action_add_poi;
|
return R.string.quick_action_add_poi;
|
||||||
|
|
||||||
|
|
|
@ -67,11 +67,13 @@ public class QuickActionRegistry {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<QuickAction> getQuickActions() {
|
public List<QuickAction> getQuickActions() {
|
||||||
List<QuickAction> actions = new ArrayList<>();
|
return new ArrayList<>(quickActions);
|
||||||
actions.addAll(quickActions);
|
|
||||||
return actions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<QuickActionType> getQuickActionTypes() {
|
||||||
|
List<QuickActionType> list = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
public List<QuickAction> getFilteredQuickActions() {
|
public List<QuickAction> getFilteredQuickActions() {
|
||||||
|
|
||||||
List<QuickAction> actions = getQuickActions();
|
List<QuickAction> actions = getQuickActions();
|
||||||
|
|
90
OsmAnd/src/net/osmand/plus/quickaction/QuickActionType.java
Normal file
90
OsmAnd/src/net/osmand/plus/quickaction/QuickActionType.java
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
package net.osmand.plus.quickaction;
|
||||||
|
|
||||||
|
import android.support.annotation.DrawableRes;
|
||||||
|
import android.support.annotation.StringRes;
|
||||||
|
|
||||||
|
public class QuickActionType {
|
||||||
|
|
||||||
|
public static final int CREATE_CATEGORY = 0;
|
||||||
|
public static final int CONFIGURE_MAP = 1;
|
||||||
|
public static final int NAVIGATION = 2;
|
||||||
|
|
||||||
|
private final int id;
|
||||||
|
private final String stringId;
|
||||||
|
private boolean actionEditable;
|
||||||
|
private @StringRes int nameRes;
|
||||||
|
private @DrawableRes int iconRes;
|
||||||
|
private Class<? extends QuickAction> cl;
|
||||||
|
private int category;
|
||||||
|
|
||||||
|
public QuickActionType(int id, String stringId) {
|
||||||
|
this.id = id;
|
||||||
|
this.stringId = stringId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public QuickActionType(int id, String stringId, Class<? extends QuickAction> cl) {
|
||||||
|
this.id = id;
|
||||||
|
this.stringId = stringId;
|
||||||
|
this.cl = cl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public QuickActionType nameRes(int nameRes) {
|
||||||
|
this.nameRes = nameRes;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public QuickActionType category(int cat) {
|
||||||
|
this.category = cat;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public QuickActionType iconRes(int iconRes) {
|
||||||
|
this.iconRes = iconRes;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public QuickActionType editable() {
|
||||||
|
actionEditable = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public QuickAction createNew() {
|
||||||
|
if(cl != null) {
|
||||||
|
try {
|
||||||
|
return cl.newInstance();
|
||||||
|
} catch (InstantiationException e) {
|
||||||
|
throw new UnsupportedOperationException(e);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
throw new UnsupportedOperationException(e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStringId() {
|
||||||
|
return stringId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isActionEditable() {
|
||||||
|
return actionEditable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNameRes() {
|
||||||
|
return nameRes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIconRes() {
|
||||||
|
return iconRes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCategory() {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,14 +13,19 @@ import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||||
import net.osmand.plus.quickaction.QuickAction;
|
import net.osmand.plus.quickaction.QuickAction;
|
||||||
|
import net.osmand.plus.quickaction.QuickActionType;
|
||||||
|
|
||||||
public class AddOSMBugAction extends QuickAction {
|
public class AddOSMBugAction extends QuickAction {
|
||||||
|
|
||||||
public static final int TYPE = 12;
|
|
||||||
|
|
||||||
private static final String KEY_MESSAGE = "message";
|
private static final String KEY_MESSAGE = "message";
|
||||||
private static final String KEY_SHO_DIALOG = "dialog";
|
private static final String KEY_SHO_DIALOG = "dialog";
|
||||||
|
|
||||||
|
public static final QuickActionType TYPE = new QuickActionType(12,
|
||||||
|
"osmbug.add", AddOSMBugAction.class).
|
||||||
|
nameRes(R.string.quick_action_add_osm_bug).iconRes(R.drawable.ic_action_bug_dark).
|
||||||
|
category(QuickActionType.CREATE_CATEGORY);
|
||||||
|
|
||||||
public AddOSMBugAction() {
|
public AddOSMBugAction() {
|
||||||
super(TYPE);
|
super(TYPE);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue