quick actions icon/name factory

This commit is contained in:
Rosty 2017-01-06 10:51:59 +02:00
parent f2cd5d945a
commit 43dec2b43b
5 changed files with 150 additions and 126 deletions

View file

@ -4,6 +4,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/spinnerListBackground"
android:orientation="vertical"> android:orientation="vertical">
<android.support.v7.widget.Toolbar <android.support.v7.widget.Toolbar
@ -15,9 +16,8 @@
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view" android:id="@+id/recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:layout_below="@id/custom_toolbar" android:layout_below="@id/custom_toolbar"
android:background="?attr/ctx_menu_info_view_bg"
android:clipToPadding="false" android:clipToPadding="false"
android:paddingTop="16dp"/> android:paddingTop="16dp"/>

View file

@ -139,7 +139,7 @@ public class AddQuickActionDialog extends DialogFragment {
HeaderViewHolder headerHolder = (HeaderViewHolder) holder; HeaderViewHolder headerHolder = (HeaderViewHolder) holder;
headerHolder.header.setText(action.nameRes); headerHolder.header.setText(action.getNameRes());
if (position == 0) headerHolder.divider.setVisibility(View.GONE); if (position == 0) headerHolder.divider.setVisibility(View.GONE);
else headerHolder.divider.setVisibility(View.VISIBLE); else headerHolder.divider.setVisibility(View.VISIBLE);
@ -147,8 +147,8 @@ public class AddQuickActionDialog extends DialogFragment {
ItemViewHolder itemHolder = (ItemViewHolder) holder; ItemViewHolder itemHolder = (ItemViewHolder) holder;
itemHolder.title.setText(action.nameRes); itemHolder.title.setText(action.getNameRes());
itemHolder.icon.setImageResource(action.iconRes); itemHolder.icon.setImageResource(action.getIconRes());
itemHolder.itemView.setOnClickListener(new View.OnClickListener() { itemHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override @Override

View file

@ -197,7 +197,7 @@ public class CreateEditActionDialog extends DialogFragment {
if (savedInstanceState == null) name.setText(action.getName(getContext())); if (savedInstanceState == null) name.setText(action.getName(getContext()));
else action.setName(name.getText().toString()); else action.setName(name.getText().toString());
image.setImageResource(action.iconRes); image.setImageResource(action.getIconRes());
} }
private void setupFooter(final View root){ private void setupFooter(final View root){

View file

@ -32,8 +32,9 @@ public class QuickAction {
protected int type; protected int type;
protected long id; protected long id;
protected @StringRes int nameRes;
protected @DrawableRes int iconRes; private @StringRes int nameRes;
private @DrawableRes int iconRes;
protected boolean autogeneratedTitle; protected boolean autogeneratedTitle;
@ -47,11 +48,14 @@ public class QuickAction {
protected QuickAction(int type, int nameRes) { protected QuickAction(int type, int nameRes) {
this.id = System.currentTimeMillis(); this.id = System.currentTimeMillis();
this.nameRes = nameRes; this.nameRes = nameRes;
this.type = type;
} }
protected QuickAction(int type) { protected QuickAction(int type) {
this.id = System.currentTimeMillis(); this.id = System.currentTimeMillis();
this.type = type; this.type = type;
this.nameRes = QuickActionFactory.getActionName(type);
this.iconRes = QuickActionFactory.getActionIcon(type);
} }
public QuickAction(QuickAction quickAction) { public QuickAction(QuickAction quickAction) {

View file

@ -6,6 +6,7 @@ import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
import android.support.v4.view.MotionEventCompat; import android.support.v4.view.MotionEventCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
@ -94,53 +95,6 @@ public class QuickActionFactory {
return quickActions != null ? quickActions : new ArrayList<QuickAction>(); return quickActions != null ? quickActions : new ArrayList<QuickAction>();
} }
public List<QuickAction> parseAndFilterActiveActionsList(String json) {
Type type = new TypeToken<List<QuickAction>>() {
}.getType();
ArrayList<QuickAction> quickActions = new Gson().fromJson(json, type);
return quickActions != null ? quickActions : new ArrayList<QuickAction>();
}
public static List<QuickAction> produceTypeActionsListWithHeaders() {
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());
quickActions.add(new MarkerAction());
if (OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class) != null) {
quickActions.add(new TakeAudioNoteAction());
quickActions.add(new TakePhotoNoteAction());
quickActions.add(new TakeVideoNoteAction());
}
if (OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null) {
quickActions.add(new AddPOIAction());
quickActions.add(new AddOSMBugAction());
}
if (OsmandPlugin.getEnabledPlugin(ParkingPositionPlugin.class) != null) {
quickActions.add(new ParkingAction());
}
quickActions.add(new QuickAction(0, R.string.quick_action_add_configure_map));
quickActions.add(new MapStyleAction());
quickActions.add(new ShowHideFavoritesAction());
quickActions.add(new ShowHidePoiAction());
quickActions.add(new QuickAction(0, R.string.quick_action_add_navigation));
quickActions.add(new NavigationVoiceAction());
return quickActions;
}
public static List<QuickAction> produceTypeActionsListWithHeaders(List<QuickAction> active) { public static List<QuickAction> produceTypeActionsListWithHeaders(List<QuickAction> active) {
ArrayList<QuickAction> quickActions = new ArrayList<>(); ArrayList<QuickAction> quickActions = new ArrayList<>();
@ -313,15 +267,130 @@ public class QuickActionFactory {
} }
} }
public static @DrawableRes int getActionIcon(int type) {
switch (type) {
case NewAction.TYPE:
return R.drawable.ic_action_plus;
case MarkerAction.TYPE:
return R.drawable.ic_action_flag_dark;
case FavoriteAction.TYPE:
return R.drawable.ic_action_fav_dark;
case ShowHideFavoritesAction.TYPE:
return R.drawable.ic_action_fav_dark;
case ShowHidePoiAction.TYPE:
return R.drawable.ic_action_gabout_dark;
case GPXAction.TYPE:
return R.drawable.ic_action_flag_dark;
case ParkingAction.TYPE:
return R.drawable.ic_action_parking_dark;
case TakeAudioNoteAction.TYPE:
return R.drawable.ic_action_micro_dark;
case TakePhotoNoteAction.TYPE:
return R.drawable.ic_action_photo_dark;
case TakeVideoNoteAction.TYPE:
return R.drawable.ic_action_video_dark;
case NavigationVoiceAction.TYPE:
return R.drawable.ic_action_volume_up;
case AddOSMBugAction.TYPE:
return R.drawable.ic_action_bug_dark;
case AddPOIAction.TYPE:
return R.drawable.ic_action_gabout_dark;
case MapStyleAction.TYPE:
return R.drawable.ic_map;
case MapSourceAction.TYPE:
return R.drawable.ic_map;
case MapOverlayAction.TYPE:
return R.drawable.ic_layer_top_dark;
case MapUnderlayAction.TYPE:
return R.drawable.ic_layer_bottom_dark;
default: return R.drawable.ic_action_plus;
}
}
public static @StringRes int getActionName(int type) {
switch (type) {
case NewAction.TYPE:
return R.string.quick_action_new_action;
case MarkerAction.TYPE:
return R.string.quick_action_add_marker;
case FavoriteAction.TYPE:
return R.string.quick_action_add_favorite;
case ShowHideFavoritesAction.TYPE:
return R.string.quick_action_showhide_favorites_title;
case ShowHidePoiAction.TYPE:
return R.string.quick_action_showhide_poi_title;
case GPXAction.TYPE:
return R.string.quick_action_add_gpx;
case ParkingAction.TYPE:
return R.string.quick_action_add_parking;
case TakeAudioNoteAction.TYPE:
return R.string.quick_action_take_audio_note;
case TakePhotoNoteAction.TYPE:
return R.string.quick_action_take_photo_note;
case TakeVideoNoteAction.TYPE:
return R.string.quick_action_take_video_note;
case NavigationVoiceAction.TYPE:
return R.string.quick_action_navigation_voice;
case AddOSMBugAction.TYPE:
return R.string.quick_action_add_osm_bug;
case AddPOIAction.TYPE:
return R.string.quick_action_add_poi;
case MapStyleAction.TYPE:
return R.string.quick_action_map_style;
case MapSourceAction.TYPE:
return R.string.quick_action_map_source;
case MapOverlayAction.TYPE:
return R.string.quick_action_map_overlay;
case MapUnderlayAction.TYPE:
return R.string.quick_action_map_underlay;
default: return R.string.quick_action_new_action;
}
}
public static class NewAction extends QuickAction { public static class NewAction extends QuickAction {
public static final int TYPE = 1; public static final int TYPE = 1;
protected NewAction() { protected NewAction() {
id = System.currentTimeMillis(); super(TYPE);
type = TYPE;
nameRes = R.string.quick_action_new_action;
iconRes = R.drawable.ic_action_plus;
} }
public NewAction(QuickAction quickAction) { public NewAction(QuickAction quickAction) {
@ -338,7 +407,6 @@ public class QuickActionFactory {
@Override @Override
public void drawUI(ViewGroup parent, MapActivity activity) { public void drawUI(ViewGroup parent, MapActivity activity) {
//TODO inflate view & fill with params
} }
} }
@ -347,10 +415,7 @@ public class QuickActionFactory {
public static final int TYPE = 2; public static final int TYPE = 2;
private MarkerAction() { private MarkerAction() {
id = System.currentTimeMillis(); super(TYPE);
type = TYPE;
nameRes = R.string.quick_action_add_marker;
iconRes = R.drawable.ic_action_flag_dark;
} }
public MarkerAction(QuickAction quickAction) { public MarkerAction(QuickAction quickAction) {
@ -400,10 +465,7 @@ public class QuickActionFactory {
public static final String KEY_CATEGORY_COLOR = "category_color"; public static final String KEY_CATEGORY_COLOR = "category_color";
private FavoriteAction() { private FavoriteAction() {
id = System.currentTimeMillis(); super(TYPE);
type = TYPE;
nameRes = R.string.quick_action_add_favorite;
iconRes = R.drawable.ic_action_fav_dark;
} }
public FavoriteAction(QuickAction quickAction) { public FavoriteAction(QuickAction quickAction) {
@ -584,10 +646,7 @@ public class QuickActionFactory {
public static final int TYPE = 4; public static final int TYPE = 4;
protected ShowHideFavoritesAction() { protected ShowHideFavoritesAction() {
id = System.currentTimeMillis(); super(TYPE);
type = TYPE;
nameRes = R.string.quick_action_showhide_favorites_title;
iconRes = R.drawable.ic_action_fav_dark;
autogeneratedTitle = true; autogeneratedTitle = true;
} }
@ -640,10 +699,7 @@ public class QuickActionFactory {
private transient EditText title; private transient EditText title;
protected ShowHidePoiAction() { protected ShowHidePoiAction() {
id = System.currentTimeMillis(); super(TYPE);
type = TYPE;
nameRes = R.string.quick_action_showhide_poi_title;
iconRes = R.drawable.ic_action_gabout_dark;
autogeneratedTitle = true; autogeneratedTitle = true;
} }
@ -946,10 +1002,7 @@ public class QuickActionFactory {
public static final String KEY_CATEGORY_COLOR = "category_color"; public static final String KEY_CATEGORY_COLOR = "category_color";
private GPXAction() { private GPXAction() {
id = System.currentTimeMillis(); super(TYPE);
type = TYPE;
nameRes = R.string.quick_action_add_gpx;
iconRes = R.drawable.ic_action_flag_dark;
} }
public GPXAction(QuickAction quickAction) { public GPXAction(QuickAction quickAction) {
@ -1108,10 +1161,7 @@ public class QuickActionFactory {
public static final int TYPE = 7; public static final int TYPE = 7;
private ParkingAction() { private ParkingAction() {
id = System.currentTimeMillis(); super(TYPE);
type = TYPE;
nameRes = R.string.quick_action_add_parking;
iconRes = R.drawable.ic_action_parking_dark;
} }
public ParkingAction(QuickAction quickAction) { public ParkingAction(QuickAction quickAction) {
@ -1150,10 +1200,7 @@ public class QuickActionFactory {
public static final int TYPE = 8; public static final int TYPE = 8;
protected TakeAudioNoteAction() { protected TakeAudioNoteAction() {
id = System.currentTimeMillis(); super(TYPE);
type = TYPE;
nameRes = R.string.quick_action_take_audio_note;
iconRes = R.drawable.ic_action_micro_dark;
} }
public TakeAudioNoteAction(QuickAction quickAction) { public TakeAudioNoteAction(QuickAction quickAction) {
@ -1189,10 +1236,7 @@ public class QuickActionFactory {
public static final int TYPE = 9; public static final int TYPE = 9;
protected TakeVideoNoteAction() { protected TakeVideoNoteAction() {
id = System.currentTimeMillis(); super(TYPE);
type = TYPE;
nameRes = R.string.quick_action_take_video_note;
iconRes = R.drawable.ic_action_video_dark;
} }
public TakeVideoNoteAction(QuickAction quickAction) { public TakeVideoNoteAction(QuickAction quickAction) {
@ -1228,10 +1272,7 @@ public class QuickActionFactory {
public static final int TYPE = 10; public static final int TYPE = 10;
protected TakePhotoNoteAction() { protected TakePhotoNoteAction() {
id = System.currentTimeMillis(); super(TYPE);
type = TYPE;
nameRes = R.string.quick_action_take_photo_note;
iconRes = R.drawable.ic_action_photo_dark;
} }
public TakePhotoNoteAction(QuickAction quickAction) { public TakePhotoNoteAction(QuickAction quickAction) {
@ -1267,11 +1308,7 @@ public class QuickActionFactory {
public static final int TYPE = 11; public static final int TYPE = 11;
protected NavigationVoiceAction() { protected NavigationVoiceAction() {
id = System.currentTimeMillis(); super(TYPE);
type = TYPE;
nameRes = R.string.quick_action_navigation_voice;
iconRes = R.drawable.ic_action_volume_up;
autogeneratedTitle = true;
} }
public NavigationVoiceAction(QuickAction quickAction) { public NavigationVoiceAction(QuickAction quickAction) {
@ -1318,10 +1355,7 @@ public class QuickActionFactory {
public static final int TYPE = 12; public static final int TYPE = 12;
protected AddOSMBugAction() { protected AddOSMBugAction() {
id = System.currentTimeMillis(); super(TYPE);
type = TYPE;
nameRes = R.string.quick_action_add_osm_bug;
iconRes = R.drawable.ic_action_bug_dark;
} }
public AddOSMBugAction(QuickAction quickAction) { public AddOSMBugAction(QuickAction quickAction) {
@ -1359,10 +1393,7 @@ public class QuickActionFactory {
public static final String KEY_TAG = "key_tag"; public static final String KEY_TAG = "key_tag";
protected AddPOIAction() { protected AddPOIAction() {
id = System.currentTimeMillis(); super(TYPE);
type = TYPE;
nameRes = R.string.quick_action_add_poi;
iconRes = R.drawable.ic_action_gabout_dark;
} }
public AddPOIAction(QuickAction quickAction) { public AddPOIAction(QuickAction quickAction) {
@ -1574,10 +1605,7 @@ public class QuickActionFactory {
private static String KEY_STYLES = "styles"; private static String KEY_STYLES = "styles";
protected MapStyleAction() { protected MapStyleAction() {
id = System.currentTimeMillis(); super(TYPE);
type = TYPE;
nameRes = R.string.quick_action_map_style;
iconRes = R.drawable.ic_map;
} }
public MapStyleAction(QuickAction quickAction) { public MapStyleAction(QuickAction quickAction) {
@ -1713,10 +1741,7 @@ public class QuickActionFactory {
private static String KEY_OVERLAYS = "overlays"; private static String KEY_OVERLAYS = "overlays";
protected MapOverlayAction() { protected MapOverlayAction() {
id = System.currentTimeMillis(); super(TYPE);
type = TYPE;
nameRes = R.string.quick_action_map_overlay;
iconRes = R.drawable.ic_layer_top_dark;
} }
public MapOverlayAction(QuickAction quickAction) { public MapOverlayAction(QuickAction quickAction) {
@ -1767,10 +1792,7 @@ public class QuickActionFactory {
private static String KEY_UNDERLAYS = "underlays"; private static String KEY_UNDERLAYS = "underlays";
protected MapUnderlayAction() { protected MapUnderlayAction() {
id = System.currentTimeMillis(); super(TYPE);
type = TYPE;
nameRes = R.string.quick_action_map_underlay;
iconRes = R.drawable.ic_layer_bottom_dark;
} }
public MapUnderlayAction(QuickAction quickAction) { public MapUnderlayAction(QuickAction quickAction) {
@ -1820,10 +1842,7 @@ public class QuickActionFactory {
private static String KEY_SOURCE = "source"; private static String KEY_SOURCE = "source";
protected MapSourceAction() { protected MapSourceAction() {
id = System.currentTimeMillis(); super(TYPE);
type = TYPE;
nameRes = R.string.quick_action_map_source;
iconRes = R.drawable.ic_map;
} }
public MapSourceAction(QuickAction quickAction) { public MapSourceAction(QuickAction quickAction) {
@ -1870,7 +1889,8 @@ public class QuickActionFactory {
private transient EditText title; private transient EditText title;
public SwitchableAction() { protected SwitchableAction(int type) {
super(type);
} }
public SwitchableAction(QuickAction quickAction) { public SwitchableAction(QuickAction quickAction) {