From c4499b1748b2d3684447e7463d2e33b6967da95e Mon Sep 17 00:00:00 2001 From: Korusn Oleksandr Date: Tue, 20 Dec 2016 16:23:40 +0200 Subject: [PATCH 01/81] quick action list pre set up --- OsmAnd/res/layout/quick_action_list.xml | 13 ++ .../res/layout/quick_action_list_header.xml | 20 +++ OsmAnd/res/layout/quick_action_list_item.xml | 83 ++++++++++ .../plus/quickaction/QuickActionItem.java | 48 ++++++ .../quickaction/QuickActionListFragment.java | 144 ++++++++++++++++++ 5 files changed, 308 insertions(+) create mode 100644 OsmAnd/res/layout/quick_action_list.xml create mode 100644 OsmAnd/res/layout/quick_action_list_header.xml create mode 100644 OsmAnd/res/layout/quick_action_list_item.xml create mode 100644 OsmAnd/src/net/osmand/plus/quickaction/QuickActionItem.java create mode 100644 OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java diff --git a/OsmAnd/res/layout/quick_action_list.xml b/OsmAnd/res/layout/quick_action_list.xml new file mode 100644 index 0000000000..e2d5b0eb1e --- /dev/null +++ b/OsmAnd/res/layout/quick_action_list.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/quick_action_list_header.xml b/OsmAnd/res/layout/quick_action_list_header.xml new file mode 100644 index 0000000000..02102aa060 --- /dev/null +++ b/OsmAnd/res/layout/quick_action_list_header.xml @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/quick_action_list_item.xml b/OsmAnd/res/layout/quick_action_list_item.xml new file mode 100644 index 0000000000..7680ad88ee --- /dev/null +++ b/OsmAnd/res/layout/quick_action_list_item.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionItem.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionItem.java new file mode 100644 index 0000000000..87629013d7 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionItem.java @@ -0,0 +1,48 @@ +package net.osmand.plus.quickaction; + +import android.support.annotation.DrawableRes; +import android.support.annotation.StringRes; + +/** + * Created by okorsun on 20.12.16. + */ + +public class QuickActionItem { + private static final int HEADER_VALUE = -1; + + private final int nameRes; + private final int drawableRes; + + public QuickActionItem(@StringRes int nameRes, @DrawableRes int drawableRes) { + this.nameRes = nameRes; + this.drawableRes = drawableRes; + } + + private QuickActionItem(){ + nameRes = HEADER_VALUE; + drawableRes = HEADER_VALUE; + } + + public static QuickActionItem createHeaderItem() { + return new QuickActionItem(); + } + + public int getNameRes() { + return nameRes; + } + + public int getDrawableRes() { + return drawableRes; + } + + public boolean isHeader() { + return nameRes == HEADER_VALUE; + } + +// public interface QuickActionListItem{ +// int getNameRes(); +// int getDrawableRes(); +// boolean isHeader(); +// } + +} diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java new file mode 100644 index 0000000000..0b23b9bcd7 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java @@ -0,0 +1,144 @@ +package net.osmand.plus.quickaction; + +import android.content.res.Resources; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.widget.RecyclerView; +import android.util.TypedValue; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import net.osmand.plus.R; +import net.osmand.plus.base.BaseOsmAndFragment; + +import java.util.ArrayList; +import java.util.List; + +import static android.util.TypedValue.COMPLEX_UNIT_DIP; + +/** + * Created by okorsun on 20.12.16. + */ + +public class QuickActionListFragment extends BaseOsmAndFragment { + + RecyclerView quickActionRV; + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.quick_action_list, container, false); + + quickActionRV = (RecyclerView) view.findViewById(R.id.recycler_view); + + + return view; + } + + + public class QuickActionAdapter extends RecyclerView.Adapter { + private static final int SCREEN_ITEM_TYPE = 1; + private static final int SCREEN_TITLE_TYPE = 2; + + private static final int ITEMS_IN_GROUP = 6; + + private List itemsList = new ArrayList<>(); + + @Override + public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + LayoutInflater inflater = LayoutInflater.from(parent.getContext()); + if (viewType == SCREEN_ITEM_TYPE) + return new QuickActionItemVH(inflater.inflate(R.layout.quick_action_list_item, parent, false)); + else + return new QuickActionHeaderVH(inflater.inflate(R.layout.quick_action_list_header, parent, false)); + } + + @Override + public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { + int viewType = getItemViewType(position); + QuickActionItem item = itemsList.get(position); + + if (viewType == SCREEN_ITEM_TYPE) { + QuickActionItemVH itemVH = (QuickActionItemVH) holder; + itemVH.icon.setImageResource(item.getDrawableRes()); + itemVH.title.setText(item.getNameRes()); + itemVH.subTitle.setText("Action" + getActionPosition(position)); //TODO: get proper string + + LinearLayout.LayoutParams dividerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + dividerParams.setMargins(isShortDivider(position) ? dpToPx(56f) : 0, 0, 0, 0); + } else { + QuickActionHeaderVH headerVH = (QuickActionHeaderVH) holder; + headerVH.headerName.setText("Screen" + (position/(ITEMS_IN_GROUP + 1) + 1)); //TODO: get proper string + } + } + + @Override + public int getItemCount() { + return itemsList.size(); + } + + @Override + public int getItemViewType(int position) { + return itemsList.get(position).isHeader() ? SCREEN_TITLE_TYPE : SCREEN_ITEM_TYPE; + } + + public void deleteItem(int position) { + itemsList.remove(position); + + notifyItemRemoved(position); + } + + + private int getActionPosition(int globalPosition) { + return globalPosition % (ITEMS_IN_GROUP + 1); + } + + private boolean isShortDivider(int globalPosition) { + return getActionPosition(globalPosition) == ITEMS_IN_GROUP || (globalPosition + 1) == getItemCount(); + } + + private int dpToPx(float dp) { + Resources r = getActivity().getResources(); + return (int) TypedValue.applyDimension( + COMPLEX_UNIT_DIP, + dp, + r.getDisplayMetrics() + ); + } + + public class QuickActionItemVH extends RecyclerView.ViewHolder { + public TextView title; + public TextView subTitle; + public ImageView icon; + public View divider; + + public QuickActionItemVH(View itemView) { + super(itemView); + title = (TextView) itemView.findViewById(R.id.title); + subTitle = (TextView) itemView.findViewById(R.id.subtitle); + icon = (ImageView) itemView.findViewById(R.id.imageView); + divider = itemView.findViewById(R.id.divider); + + itemView.findViewById(R.id.closeImageButton).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + QuickActionAdapter.this.deleteItem(getAdapterPosition()); + } + }); + } + } + + public class QuickActionHeaderVH extends RecyclerView.ViewHolder { + public TextView headerName; + + public QuickActionHeaderVH(View itemView) { + super(itemView); + headerName = (TextView) itemView.findViewById(R.id.header); + } + } + } +} From 481ea7551c26a0e2ea4bec379e1942b89386c065 Mon Sep 17 00:00:00 2001 From: Korusn Oleksandr Date: Tue, 20 Dec 2016 17:57:14 +0200 Subject: [PATCH 02/81] add button to configure screen (not propper one) --- .../views/mapwidgets/MapWidgetRegistry.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java index 6881cd3142..d647306a4b 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java @@ -24,6 +24,7 @@ import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dialogs.ConfigureMapMenu; +import net.osmand.plus.quickaction.QuickActionListFragment; import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapTileView; @@ -36,7 +37,6 @@ import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; import java.util.TreeSet; -import java.util.zip.GZIPOutputStream; public class MapWidgetRegistry { @@ -358,6 +358,7 @@ public class MapWidgetRegistry { public void addControls(MapActivity map, ContextMenuAdapter cm, ApplicationMode mode) { + addQuickActionControl(map, cm, mode); // Right panel cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_right, map) .setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem()); @@ -384,6 +385,37 @@ public class MapWidgetRegistry { return leftWidgetSet; } + private void addQuickActionControl(final MapActivity mapActivity, final ContextMenuAdapter contextMenuAdapter, + final ApplicationMode mode) { + boolean selected = true; + contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder() // TODO: add top margin and proper data + .setTitleId(R.string.av_video_quality_high, mapActivity) + .setIcon(R.drawable.ic_action_quit_dark) + .setSelected(selected) + .setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) + .setSecondaryIcon(/*r.widget != null*/ true ? R.drawable.ic_action_additional_option : ContextMenuItem.INVALID_ID) + .setListener(new ContextMenuAdapter.OnRowItemClick() { + @Override + public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int position, boolean isChecked) { + return false; + } + + @Override + public boolean onRowItemClick(ArrayAdapter adapter, View view, int itemId, int position) { + int slideInAnim = R.anim.slide_in_bottom; + int slideOutAnim = R.anim.slide_out_bottom; + + mapActivity.getSupportFragmentManager().beginTransaction() + .setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim) + .add(R.id.fragmentContainer, new QuickActionListFragment(), QuickActionListFragment.TAG) + .addToBackStack(QuickActionListFragment.TAG).commitAllowingStateLoss(); + + return true; + } + }) + .createItem()); + } + private void addControls(final MapActivity mapActivity, final ContextMenuAdapter contextMenuAdapter, Set groupTitle, final ApplicationMode mode) { for (final MapWidgetRegInfo r : groupTitle) { From 368bb2738f619eafbde8a3aea9ee8ddfcef1539b Mon Sep 17 00:00:00 2001 From: Korusn Oleksandr Date: Tue, 20 Dec 2016 19:26:34 +0200 Subject: [PATCH 03/81] working on quick action list --- OsmAnd/res/layout/quick_action_list.xml | 1 + .../res/layout/quick_action_list_header.xml | 3 +- OsmAnd/res/layout/quick_action_list_item.xml | 5 ++- .../quickaction/QuickActionListFragment.java | 39 ++++++++++++++++++- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/OsmAnd/res/layout/quick_action_list.xml b/OsmAnd/res/layout/quick_action_list.xml index e2d5b0eb1e..3bc404f17b 100644 --- a/OsmAnd/res/layout/quick_action_list.xml +++ b/OsmAnd/res/layout/quick_action_list.xml @@ -8,6 +8,7 @@ android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="?attr/ctx_menu_info_view_bg" /> \ No newline at end of file diff --git a/OsmAnd/res/layout/quick_action_list_header.xml b/OsmAnd/res/layout/quick_action_list_header.xml index 02102aa060..1af77b5d88 100644 --- a/OsmAnd/res/layout/quick_action_list_header.xml +++ b/OsmAnd/res/layout/quick_action_list_header.xml @@ -2,10 +2,11 @@ diff --git a/OsmAnd/res/layout/quick_action_list_item.xml b/OsmAnd/res/layout/quick_action_list_item.xml index 7680ad88ee..9bb826a140 100644 --- a/OsmAnd/res/layout/quick_action_list_item.xml +++ b/OsmAnd/res/layout/quick_action_list_item.xml @@ -2,6 +2,7 @@ @@ -20,7 +21,7 @@ android:layout_marginRight="4dp" android:focusable="false" android:scaleType="centerInside" - android:src="@drawable/map_drawer" + android:src="@drawable/ic_action_reorder" android:visibility="gone" tools:visibility="visible"/> @@ -69,7 +70,7 @@ android:layout_gravity="center_vertical" android:layout_marginLeft="8dp" android:layout_marginRight="16dp" - android:src="@drawable/ic_action_close_dark" + android:src="@drawable/ic_action_remove_dark" android:scaleType="centerInside"/> diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java index 0b23b9bcd7..2f6bee7c39 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java @@ -3,6 +3,7 @@ package net.osmand.plus.quickaction; import android.content.res.Resources; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.TypedValue; import android.view.LayoutInflater; @@ -25,8 +26,10 @@ import static android.util.TypedValue.COMPLEX_UNIT_DIP; */ public class QuickActionListFragment extends BaseOsmAndFragment { + public static final String TAG = QuickActionListFragment.class.getSimpleName(); RecyclerView quickActionRV; + QuickActionAdapter adapter; @Nullable @Override @@ -34,11 +37,30 @@ public class QuickActionListFragment extends BaseOsmAndFragment { View view = inflater.inflate(R.layout.quick_action_list, container, false); quickActionRV = (RecyclerView) view.findViewById(R.id.recycler_view); +// quickActionRV.setBackgroundColor( +// getResources().getColor( +// getMyApplication().getSettings().isLightContent() ? R.color.bg_color_light +// : R.color.bg_color_dark)); + adapter = new QuickActionAdapter(); + quickActionRV.setAdapter(adapter); + quickActionRV.setLayoutManager(new LinearLayoutManager(getContext())); + + adapter.addItems(createMockDada()); + return view; } + private List createMockDada() { + List result = new ArrayList<>(); + for (int i = 0; i < 15; i ++){ + result.add(new QuickActionItem(R.string.favorite, R.drawable.ic_action_flag_dark)); + } + + return result; + } + public class QuickActionAdapter extends RecyclerView.Adapter { private static final int SCREEN_ITEM_TYPE = 1; @@ -66,13 +88,13 @@ public class QuickActionListFragment extends BaseOsmAndFragment { QuickActionItemVH itemVH = (QuickActionItemVH) holder; itemVH.icon.setImageResource(item.getDrawableRes()); itemVH.title.setText(item.getNameRes()); - itemVH.subTitle.setText("Action" + getActionPosition(position)); //TODO: get proper string + itemVH.subTitle.setText("Action " + getActionPosition(position)); //TODO: get proper string LinearLayout.LayoutParams dividerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); dividerParams.setMargins(isShortDivider(position) ? dpToPx(56f) : 0, 0, 0, 0); } else { QuickActionHeaderVH headerVH = (QuickActionHeaderVH) holder; - headerVH.headerName.setText("Screen" + (position/(ITEMS_IN_GROUP + 1) + 1)); //TODO: get proper string + headerVH.headerName.setText("Screen " + (position/(ITEMS_IN_GROUP + 1) + 1)); //TODO: get proper string } } @@ -92,6 +114,19 @@ public class QuickActionListFragment extends BaseOsmAndFragment { notifyItemRemoved(position); } + public void addItems(List data) { + List resultList = new ArrayList<>(); + for (int i = 0; i < data.size(); i++) { + if (i % ITEMS_IN_GROUP == 0) + resultList.add(QuickActionItem.createHeaderItem()); + + resultList.add(data.get(i)); + } + + itemsList = resultList; + notifyDataSetChanged(); + } + private int getActionPosition(int globalPosition) { return globalPosition % (ITEMS_IN_GROUP + 1); From 7af5c8c20b6dfcfaa11134d2210a8cdf9df2b92d Mon Sep 17 00:00:00 2001 From: Korusn Oleksandr Date: Wed, 21 Dec 2016 18:13:50 +0200 Subject: [PATCH 04/81] button on configure screen ready --- .../list_group_empty_title_with_switch.xml | 52 +++++++++++++++++++ OsmAnd/res/values/strings.xml | 3 ++ .../QuickActionItemTouchHelperCallback.java | 8 +++ .../views/mapwidgets/MapWidgetRegistry.java | 28 ++++++++-- 4 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 OsmAnd/res/layout/list_group_empty_title_with_switch.xml create mode 100644 OsmAnd/src/net/osmand/plus/quickaction/QuickActionItemTouchHelperCallback.java diff --git a/OsmAnd/res/layout/list_group_empty_title_with_switch.xml b/OsmAnd/res/layout/list_group_empty_title_with_switch.xml new file mode 100644 index 0000000000..bb4418505d --- /dev/null +++ b/OsmAnd/res/layout/list_group_empty_title_with_switch.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index b0c98f937e..f67f962a0a 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -2456,4 +2456,7 @@ If you need help with OsmAnd application, please contact our support team: suppo Number of edits Report for File name contains illegal character + Quick action + Action %d + Screen %d diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionItemTouchHelperCallback.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionItemTouchHelperCallback.java new file mode 100644 index 0000000000..67ba29223b --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionItemTouchHelperCallback.java @@ -0,0 +1,8 @@ +package net.osmand.plus.quickaction; + +/** + * Created by okorsun on 21.12.16. + */ + +public class QuickActionItemTouchHelperCallback { +} diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java index d647306a4b..b0717cfc8a 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java @@ -387,16 +387,21 @@ public class MapWidgetRegistry { private void addQuickActionControl(final MapActivity mapActivity, final ContextMenuAdapter contextMenuAdapter, final ApplicationMode mode) { + + contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_right, mapActivity) + .setCategory(true).setLayout(R.layout.list_group_empty_title_with_switch).createItem()); + boolean selected = true; - contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder() // TODO: add top margin and proper data - .setTitleId(R.string.av_video_quality_high, mapActivity) - .setIcon(R.drawable.ic_action_quit_dark) + contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.configure_screen_quick_action, mapActivity) + .setIcon(R.drawable.map_quick_action) .setSelected(selected) .setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) - .setSecondaryIcon(/*r.widget != null*/ true ? R.drawable.ic_action_additional_option : ContextMenuItem.INVALID_ID) + .setSecondaryIcon( R.drawable.ic_action_additional_option) .setListener(new ContextMenuAdapter.OnRowItemClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int position, boolean isChecked) { + setVisibility(adapter, position, isChecked, false); return false; } @@ -412,6 +417,21 @@ public class MapWidgetRegistry { return true; } + + private void setVisibility(ArrayAdapter adapter, + int position, + boolean visible, + boolean collapsed) { +// MapWidgetRegistry.this.setVisibility(r, visible, collapsed); + MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer(); + if (mil != null) { + mil.recreateControls(); + } + ContextMenuItem item = adapter.getItem(position); + item.setSelected(visible); + item.setColorRes(visible ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); + adapter.notifyDataSetChanged(); + } }) .createItem()); } From 86ba0403f89dda4a81a17463af29d1b5a74c589f Mon Sep 17 00:00:00 2001 From: Korusn Oleksandr Date: Wed, 21 Dec 2016 18:14:51 +0200 Subject: [PATCH 05/81] actions list drag and drop implemented --- OsmAnd/res/layout/quick_action_list.xml | 6 + OsmAnd/res/layout/quick_action_list_item.xml | 6 +- .../QuickActionItemTouchHelperCallback.java | 47 +++++++- .../quickaction/QuickActionListFragment.java | 110 ++++++++++++++++-- 4 files changed, 154 insertions(+), 15 deletions(-) diff --git a/OsmAnd/res/layout/quick_action_list.xml b/OsmAnd/res/layout/quick_action_list.xml index 3bc404f17b..66997f59e6 100644 --- a/OsmAnd/res/layout/quick_action_list.xml +++ b/OsmAnd/res/layout/quick_action_list.xml @@ -4,6 +4,12 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + + + android:src="@drawable/ic_action_reorder"/> createMockDada() { List result = new ArrayList<>(); - for (int i = 0; i < 15; i ++){ + for (int i = 0; i < 5; i ++){ result.add(new QuickActionItem(R.string.favorite, R.drawable.ic_action_flag_dark)); + result.add(new QuickActionItem(R.string.poi, R.drawable.ic_action_flag_dark)); + result.add(new QuickActionItem(R.string.map_marker, R.drawable.ic_action_flag_dark)); } return result; } + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + super.onCreateOptionsMenu(menu, inflater); + } - public class QuickActionAdapter extends RecyclerView.Adapter { - private static final int SCREEN_ITEM_TYPE = 1; - private static final int SCREEN_TITLE_TYPE = 2; + public class QuickActionAdapter extends RecyclerView.Adapter implements QuickActionItemTouchHelperCallback.OnItemMoveCallback { + public static final int SCREEN_ITEM_TYPE = 1; + public static final int SCREEN_HEADER_TYPE = 2; private static final int ITEMS_IN_GROUP = 6; private List itemsList = new ArrayList<>(); + private final OnStartDragListener onStartDragListener; + + public QuickActionAdapter(OnStartDragListener onStartDragListener){ + this.onStartDragListener = onStartDragListener; + } @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { @@ -85,16 +131,29 @@ public class QuickActionListFragment extends BaseOsmAndFragment { QuickActionItem item = itemsList.get(position); if (viewType == SCREEN_ITEM_TYPE) { - QuickActionItemVH itemVH = (QuickActionItemVH) holder; - itemVH.icon.setImageResource(item.getDrawableRes()); + final QuickActionItemVH itemVH = (QuickActionItemVH) holder; + itemVH.title.setText(item.getNameRes()); - itemVH.subTitle.setText("Action " + getActionPosition(position)); //TODO: get proper string + itemVH.subTitle.setText(getResources().getString(R.string.quick_action_item_action, getActionPosition(position))); + + itemVH.icon.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(item.getDrawableRes())); + itemVH.handleView.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_reorder)); + itemVH.handleView.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + if (MotionEventCompat.getActionMasked(event) == + MotionEvent.ACTION_DOWN) { + onStartDragListener.onStartDrag(itemVH); + } + return false; + } + }); LinearLayout.LayoutParams dividerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); dividerParams.setMargins(isShortDivider(position) ? dpToPx(56f) : 0, 0, 0, 0); } else { QuickActionHeaderVH headerVH = (QuickActionHeaderVH) holder; - headerVH.headerName.setText("Screen " + (position/(ITEMS_IN_GROUP + 1) + 1)); //TODO: get proper string + headerVH.headerName.setText(getResources().getString(R.string.quick_action_item_action, position/(ITEMS_IN_GROUP + 1) + 1)); } } @@ -105,7 +164,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment { @Override public int getItemViewType(int position) { - return itemsList.get(position).isHeader() ? SCREEN_TITLE_TYPE : SCREEN_ITEM_TYPE; + return itemsList.get(position).isHeader() ? SCREEN_HEADER_TYPE : SCREEN_ITEM_TYPE; } public void deleteItem(int position) { @@ -145,11 +204,36 @@ public class QuickActionListFragment extends BaseOsmAndFragment { ); } + @Override + public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { + if (viewHolder.getItemViewType() == SCREEN_HEADER_TYPE || target.getItemViewType() == SCREEN_HEADER_TYPE) + return false; + else { + int selectedPosition = viewHolder.getAdapterPosition(); + int targetPosition = target.getAdapterPosition(); + + Collections.swap(itemsList, selectedPosition, targetPosition); + if (selectedPosition - targetPosition < -1){ + notifyItemMoved(selectedPosition, targetPosition); + notifyItemMoved(targetPosition - 1, selectedPosition); + } else if (selectedPosition - targetPosition > 1) { + notifyItemMoved(selectedPosition, targetPosition); + notifyItemMoved(targetPosition + 1, selectedPosition); + } else { + notifyItemMoved(selectedPosition, targetPosition); + } + notifyItemChanged(selectedPosition); + notifyItemChanged(targetPosition); + return true; + } + } + public class QuickActionItemVH extends RecyclerView.ViewHolder { public TextView title; public TextView subTitle; public ImageView icon; public View divider; + public ImageView handleView; public QuickActionItemVH(View itemView) { super(itemView); @@ -157,6 +241,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment { subTitle = (TextView) itemView.findViewById(R.id.subtitle); icon = (ImageView) itemView.findViewById(R.id.imageView); divider = itemView.findViewById(R.id.divider); + handleView = (ImageView) itemView.findViewById(R.id.handle_view); itemView.findViewById(R.id.closeImageButton).setOnClickListener(new View.OnClickListener() { @Override @@ -164,6 +249,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment { QuickActionAdapter.this.deleteItem(getAdapterPosition()); } }); + } } @@ -176,4 +262,8 @@ public class QuickActionListFragment extends BaseOsmAndFragment { } } } + + public interface OnStartDragListener { + void onStartDrag(RecyclerView.ViewHolder viewHolder); + } } From 4c71648a73e1c3d0a3a1a3dbd90d78ffebf4c35f Mon Sep 17 00:00:00 2001 From: Korusn Oleksandr Date: Wed, 21 Dec 2016 19:57:15 +0200 Subject: [PATCH 06/81] fab added --- OsmAnd/res/layout/quick_action_list.xml | 28 +++++++++++++------ .../res/layout/quick_action_list_header.xml | 8 ++---- .../quickaction/QuickActionListFragment.java | 24 +++++++++++++--- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/OsmAnd/res/layout/quick_action_list.xml b/OsmAnd/res/layout/quick_action_list.xml index 66997f59e6..2af09bc0f6 100644 --- a/OsmAnd/res/layout/quick_action_list.xml +++ b/OsmAnd/res/layout/quick_action_list.xml @@ -1,20 +1,32 @@ - + + android:layout_height="?android:attr/actionBarSize" + android:background="@color/actionbar_light_color"/> + android:clipToPadding="false" + android:paddingTop="16dp"/> - \ No newline at end of file + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/quick_action_list_header.xml b/OsmAnd/res/layout/quick_action_list_header.xml index 1af77b5d88..937b1041fe 100644 --- a/OsmAnd/res/layout/quick_action_list_header.xml +++ b/OsmAnd/res/layout/quick_action_list_header.xml @@ -2,18 +2,16 @@ + android:background="?attr/bg_color"> diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java index 48c4c1444f..cb1d05ec2b 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java @@ -5,6 +5,7 @@ import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.design.widget.FloatingActionButton; import android.support.v4.content.ContextCompat; import android.support.v4.view.MotionEventCompat; import android.support.v7.widget.LinearLayoutManager; @@ -22,7 +23,6 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.base.BaseOsmAndFragment; @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import static android.R.attr.scrollY; import static android.util.TypedValue.COMPLEX_UNIT_DIP; import static net.osmand.plus.R.id.toolbar; @@ -40,9 +41,10 @@ import static net.osmand.plus.R.id.toolbar; public class QuickActionListFragment extends BaseOsmAndFragment { public static final String TAG = QuickActionListFragment.class.getSimpleName(); - RecyclerView quickActionRV; QuickActionAdapter adapter; ItemTouchHelper touchHelper; + RecyclerView quickActionRV; + FloatingActionButton fab; @Nullable @Override @@ -68,9 +70,23 @@ public class QuickActionListFragment extends BaseOsmAndFragment { ItemTouchHelper.Callback touchHelperCallback = new QuickActionItemTouchHelperCallback(adapter); touchHelper = new ItemTouchHelper(touchHelperCallback); touchHelper.attachToRecyclerView(quickActionRV); - - adapter.addItems(createMockDada()); + + fab = (FloatingActionButton) view.findViewById(R.id.fabButton); + quickActionRV.setOnScrollListener(new RecyclerView.OnScrollListener() { + }); + quickActionRV.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(RecyclerView recyclerView, int dx, int dy) { + if (dy > 0 && fab.getVisibility() == View.VISIBLE) + fab.hide(); + else if (dy < 0 && fab.getVisibility() != View.VISIBLE) + fab.show(); + } + }); + + + Toolbar toolbar = (Toolbar) view.findViewById(R.id.custom_toolbar); Drawable back = getMyApplication().getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha); back.setColorFilter(ContextCompat.getColor(getContext(), R.color.color_white), PorterDuff.Mode.MULTIPLY); From 087f47efc47e528347256e5602b46ab5afcd9dcf Mon Sep 17 00:00:00 2001 From: Korusn Oleksandr Date: Thu, 22 Dec 2016 13:06:49 +0200 Subject: [PATCH 07/81] actions list delete fix --- .../quickaction/QuickActionListFragment.java | 51 +++++++++++++++---- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java index cb1d05ec2b..67d08b0e6c 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java @@ -32,6 +32,7 @@ import java.util.List; import static android.R.attr.scrollY; import static android.util.TypedValue.COMPLEX_UNIT_DIP; +import static net.osmand.plus.R.id.index_item; import static net.osmand.plus.R.id.toolbar; /** @@ -142,7 +143,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment { } @Override - public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { + public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); QuickActionItem item = itemsList.get(position); @@ -153,7 +154,6 @@ public class QuickActionListFragment extends BaseOsmAndFragment { itemVH.subTitle.setText(getResources().getString(R.string.quick_action_item_action, getActionPosition(position))); itemVH.icon.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(item.getDrawableRes())); - itemVH.handleView.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_reorder)); itemVH.handleView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { @@ -164,12 +164,18 @@ public class QuickActionListFragment extends BaseOsmAndFragment { return false; } }); + itemVH.closeBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + QuickActionAdapter.this.deleteItem(holder.getAdapterPosition()); + } + }); LinearLayout.LayoutParams dividerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); dividerParams.setMargins(isShortDivider(position) ? dpToPx(56f) : 0, 0, 0, 0); } else { QuickActionHeaderVH headerVH = (QuickActionHeaderVH) holder; - headerVH.headerName.setText(getResources().getString(R.string.quick_action_item_action, position/(ITEMS_IN_GROUP + 1) + 1)); + headerVH.headerName.setText(getResources().getString(R.string.quick_action_item_screen, position/(ITEMS_IN_GROUP + 1) + 1)); } } @@ -185,8 +191,30 @@ public class QuickActionListFragment extends BaseOsmAndFragment { public void deleteItem(int position) { itemsList.remove(position); - notifyItemRemoved(position); + + for (int i = position; i < itemsList.size(); i++ ){ + if (getItemViewType(i) == SCREEN_HEADER_TYPE) { + if (i != itemsList.size() - 2){ + Collections.swap(itemsList, i, i +1); + notifyItemMoved(i, i + 1); + i++; + } else { + itemsList.remove(i); + notifyItemRemoved(i); + } + } + } + notifyItemRangeChanged(position, itemsList.size() - position); + + LinearLayoutManager layoutManager = (LinearLayoutManager) quickActionRV.getLayoutManager(); + int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition(); + + if ((lastVisibleItemPosition == itemsList.size() - 1 || lastVisibleItemPosition == itemsList.size()) && + layoutManager.findFirstVisibleItemPosition() == 0 && + fab.getVisibility() != View.VISIBLE || + itemsList.size() == 0) + fab.show(); } public void addItems(List data) { @@ -211,6 +239,10 @@ public class QuickActionListFragment extends BaseOsmAndFragment { return getActionPosition(globalPosition) == ITEMS_IN_GROUP || (globalPosition + 1) == getItemCount(); } + public boolean isRecyclerScrollable(RecyclerView recyclerView) { + return recyclerView.computeHorizontalScrollRange() > recyclerView.getWidth() || recyclerView.computeVerticalScrollRange() > recyclerView.getHeight(); + } + private int dpToPx(float dp) { Resources r = getActivity().getResources(); return (int) TypedValue.applyDimension( @@ -250,6 +282,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment { public ImageView icon; public View divider; public ImageView handleView; + public ImageView closeBtn; public QuickActionItemVH(View itemView) { super(itemView); @@ -258,14 +291,10 @@ public class QuickActionListFragment extends BaseOsmAndFragment { icon = (ImageView) itemView.findViewById(R.id.imageView); divider = itemView.findViewById(R.id.divider); handleView = (ImageView) itemView.findViewById(R.id.handle_view); + closeBtn = (ImageView) itemView.findViewById(R.id.closeImageButton); - itemView.findViewById(R.id.closeImageButton).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - QuickActionAdapter.this.deleteItem(getAdapterPosition()); - } - }); - + handleView.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_reorder)); + closeBtn.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark)); } } From f774480c0397e4e67c306adf13f61a9f5eba5d22 Mon Sep 17 00:00:00 2001 From: Korusn Oleksandr Date: Thu, 22 Dec 2016 14:36:27 +0200 Subject: [PATCH 08/81] delete fix --- .../plus/quickaction/QuickActionListFragment.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java index 67d08b0e6c..a5cbb6ba14 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java @@ -190,6 +190,9 @@ public class QuickActionListFragment extends BaseOsmAndFragment { } public void deleteItem(int position) { + if (position == -1) + return; + itemsList.remove(position); notifyItemRemoved(position); @@ -207,9 +210,12 @@ public class QuickActionListFragment extends BaseOsmAndFragment { } notifyItemRangeChanged(position, itemsList.size() - position); - LinearLayoutManager layoutManager = (LinearLayoutManager) quickActionRV.getLayoutManager(); - int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition(); + showFABIfNotScrollable(); + } + private void showFABIfNotScrollable() { + LinearLayoutManager layoutManager = (LinearLayoutManager) quickActionRV.getLayoutManager(); + int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition(); if ((lastVisibleItemPosition == itemsList.size() - 1 || lastVisibleItemPosition == itemsList.size()) && layoutManager.findFirstVisibleItemPosition() == 0 && fab.getVisibility() != View.VISIBLE || From 7c677beea99b7be753d7f47a5b249629f897bf87 Mon Sep 17 00:00:00 2001 From: Korusn Oleksandr Date: Thu, 22 Dec 2016 16:05:06 +0200 Subject: [PATCH 09/81] adding items --- OsmAnd/res/layout/quick_action_list.xml | 6 +- .../quickaction/QuickActionListFragment.java | 87 ++++++++++++------- 2 files changed, 60 insertions(+), 33 deletions(-) diff --git a/OsmAnd/res/layout/quick_action_list.xml b/OsmAnd/res/layout/quick_action_list.xml index 2af09bc0f6..3f1bc621bb 100644 --- a/OsmAnd/res/layout/quick_action_list.xml +++ b/OsmAnd/res/layout/quick_action_list.xml @@ -1,6 +1,7 @@ @@ -14,8 +15,8 @@ @@ -27,6 +28,7 @@ android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_margin="16dp" - android:src="@drawable/map_quick_action"/> + android:src="@drawable/map_quick_action" + app:backgroundTint="@color/dashboard_blue"/> \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java index a5cbb6ba14..08043b70fc 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java @@ -1,5 +1,7 @@ package net.osmand.plus.quickaction; +import android.app.Activity; +import android.content.Context; import android.content.res.Resources; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; @@ -14,8 +16,6 @@ import android.support.v7.widget.Toolbar; import android.support.v7.widget.helper.ItemTouchHelper; import android.util.TypedValue; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; @@ -24,16 +24,14 @@ import android.widget.LinearLayout; import android.widget.TextView; import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.BaseOsmAndFragment; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import static android.R.attr.scrollY; import static android.util.TypedValue.COMPLEX_UNIT_DIP; -import static net.osmand.plus.R.id.index_item; -import static net.osmand.plus.R.id.toolbar; /** * Created by okorsun on 20.12.16. @@ -42,23 +40,35 @@ import static net.osmand.plus.R.id.toolbar; public class QuickActionListFragment extends BaseOsmAndFragment { public static final String TAG = QuickActionListFragment.class.getSimpleName(); - QuickActionAdapter adapter; - ItemTouchHelper touchHelper; - RecyclerView quickActionRV; + RecyclerView quickActionRV; FloatingActionButton fab; + QuickActionAdapter adapter; + ItemTouchHelper touchHelper; + @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.quick_action_list, container, false); quickActionRV = (RecyclerView) view.findViewById(R.id.recycler_view); -// quickActionRV.setBackgroundColor( -// getResources().getColor( -// getMyApplication().getSettings().isLightContent() ? R.color.bg_color_light -// : R.color.bg_color_dark)); + fab = (FloatingActionButton) view.findViewById(R.id.fabButton); + setUpQuickActionRV(); + fab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + adapter.addItem(new QuickActionItem(R.string.map_marker, R.drawable.ic_action_flag_dark)); + } + }); + + setUpToolbar(view); + + return view; + } + + private void setUpQuickActionRV() { adapter = new QuickActionAdapter(new OnStartDragListener() { @Override public void onStartDrag(RecyclerView.ViewHolder viewHolder) { @@ -73,9 +83,6 @@ public class QuickActionListFragment extends BaseOsmAndFragment { touchHelper.attachToRecyclerView(quickActionRV); adapter.addItems(createMockDada()); - fab = (FloatingActionButton) view.findViewById(R.id.fabButton); - quickActionRV.setOnScrollListener(new RecyclerView.OnScrollListener() { - }); quickActionRV.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { @@ -85,10 +92,10 @@ public class QuickActionListFragment extends BaseOsmAndFragment { fab.show(); } }); + } - - - Toolbar toolbar = (Toolbar) view.findViewById(R.id.custom_toolbar); + private void setUpToolbar(View view) { + Toolbar toolbar = (Toolbar) view.findViewById(R.id.custom_toolbar); Drawable back = getMyApplication().getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha); back.setColorFilter(ContextCompat.getColor(getContext(), R.color.color_white), PorterDuff.Mode.MULTIPLY); toolbar.setNavigationIcon(back); @@ -100,13 +107,11 @@ public class QuickActionListFragment extends BaseOsmAndFragment { }); toolbar.setTitle(R.string.configure_screen_quick_action); toolbar.setTitleTextColor(ContextCompat.getColor(getContext(), R.color.color_white)); - - return view; } private List createMockDada() { List result = new ArrayList<>(); - for (int i = 0; i < 5; i ++){ + for (int i = 0; i < 3; i++) { result.add(new QuickActionItem(R.string.favorite, R.drawable.ic_action_flag_dark)); result.add(new QuickActionItem(R.string.poi, R.drawable.ic_action_flag_dark)); result.add(new QuickActionItem(R.string.map_marker, R.drawable.ic_action_flag_dark)); @@ -116,10 +121,22 @@ public class QuickActionListFragment extends BaseOsmAndFragment { } @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - super.onCreateOptionsMenu(menu, inflater); + public void onAttach(Context context) { + super.onAttach(context); + getMapActivity().disableDrawer(); } + @Override + public void onDetach() { + super.onDetach(); + getMapActivity().enableDrawer(); + } + + private MapActivity getMapActivity() { + return (MapActivity) getActivity(); + } + + public class QuickActionAdapter extends RecyclerView.Adapter implements QuickActionItemTouchHelperCallback.OnItemMoveCallback { public static final int SCREEN_ITEM_TYPE = 1; public static final int SCREEN_HEADER_TYPE = 2; @@ -129,7 +146,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment { private List itemsList = new ArrayList<>(); private final OnStartDragListener onStartDragListener; - public QuickActionAdapter(OnStartDragListener onStartDragListener){ + public QuickActionAdapter(OnStartDragListener onStartDragListener) { this.onStartDragListener = onStartDragListener; } @@ -175,7 +192,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment { dividerParams.setMargins(isShortDivider(position) ? dpToPx(56f) : 0, 0, 0, 0); } else { QuickActionHeaderVH headerVH = (QuickActionHeaderVH) holder; - headerVH.headerName.setText(getResources().getString(R.string.quick_action_item_screen, position/(ITEMS_IN_GROUP + 1) + 1)); + headerVH.headerName.setText(getResources().getString(R.string.quick_action_item_screen, position / (ITEMS_IN_GROUP + 1) + 1)); } } @@ -196,10 +213,10 @@ public class QuickActionListFragment extends BaseOsmAndFragment { itemsList.remove(position); notifyItemRemoved(position); - for (int i = position; i < itemsList.size(); i++ ){ + for (int i = position; i < itemsList.size(); i++) { if (getItemViewType(i) == SCREEN_HEADER_TYPE) { - if (i != itemsList.size() - 2){ - Collections.swap(itemsList, i, i +1); + if (i != itemsList.size() - 2) { + Collections.swap(itemsList, i, i + 1); notifyItemMoved(i, i + 1); i++; } else { @@ -236,6 +253,14 @@ public class QuickActionListFragment extends BaseOsmAndFragment { notifyDataSetChanged(); } + public void addItem(QuickActionItem item) { + int oldSize = itemsList.size(); + if (oldSize % (ITEMS_IN_GROUP + 1) == 0) + itemsList.add(QuickActionItem.createHeaderItem()); + itemsList.add(item); + notifyItemRangeInserted(oldSize, itemsList.size() - oldSize); + } + private int getActionPosition(int globalPosition) { return globalPosition % (ITEMS_IN_GROUP + 1); @@ -264,10 +289,10 @@ public class QuickActionListFragment extends BaseOsmAndFragment { return false; else { int selectedPosition = viewHolder.getAdapterPosition(); - int targetPosition = target.getAdapterPosition(); + int targetPosition = target.getAdapterPosition(); Collections.swap(itemsList, selectedPosition, targetPosition); - if (selectedPosition - targetPosition < -1){ + if (selectedPosition - targetPosition < -1) { notifyItemMoved(selectedPosition, targetPosition); notifyItemMoved(targetPosition - 1, selectedPosition); } else if (selectedPosition - targetPosition > 1) { @@ -286,7 +311,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment { public TextView title; public TextView subTitle; public ImageView icon; - public View divider; + public View divider; public ImageView handleView; public ImageView closeBtn; From 90926e042e14d4f5631c344fb00facd136607d7a Mon Sep 17 00:00:00 2001 From: Rosty Date: Thu, 22 Dec 2016 16:06:27 +0200 Subject: [PATCH 10/81] quick action model/factory/prefs --- OsmAnd/res/values/strings.xml | 2 + .../src/net/osmand/plus/OsmandSettings.java | 4 + .../osmand/plus/quickaction/QuickAction.java | 43 +++++++ .../plus/quickaction/QuickActionFactory.java | 107 ++++++++++++++++++ .../quickaction/QuickActionListFragment.java | 13 +++ .../views/mapwidgets/MapWidgetRegistry.java | 14 +-- 6 files changed, 176 insertions(+), 7 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java create mode 100644 OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 7a07f53041..caca4b5bf1 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -2466,4 +2466,6 @@ If you need help with OsmAnd application, please contact our support team: suppo Quick action Action %d Screen %d + Add marker + Add favorite diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 71810016a6..dca8001cec 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1101,6 +1101,10 @@ public class OsmandSettings { } } + public final CommonPreference QUICK_ACTION = new BooleanPreference("quick_action", false).makeProfile(); + + public final CommonPreference QUICK_ACTION_LIST = new StringPreference("quick_action_list", "").makeProfile(); + public final OsmandPreference OSMO_DEVICE_KEY = new StringPreference("osmo_device_token", "").makeGlobal(); public final OsmandPreference OSMO_USER_NAME = new StringPreference("osmo_user_name", "").makeGlobal(); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java new file mode 100644 index 0000000000..b8938987a0 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java @@ -0,0 +1,43 @@ +package net.osmand.plus.quickaction; + + +import android.support.annotation.DrawableRes; +import android.support.annotation.StringRes; +import android.view.ViewGroup; + +import java.util.HashMap; + +public class QuickAction { + + protected int id; + protected @StringRes int nameRes; + protected @DrawableRes int iconRes; + + private HashMap params; + + protected QuickAction() { + } + + public QuickAction(QuickAction quickAction) { + this.id = quickAction.id; + this.nameRes = quickAction.nameRes; + this.iconRes = quickAction.iconRes; + this.params = quickAction.params; + } + + public int getNameRes() { + return nameRes; + } + + public int getIconRes() { + return iconRes; + } + + public HashMap getParams() { + return params; + } + + public void execute(){}; + public void drawUI(ViewGroup parent){}; +} + diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java new file mode 100644 index 0000000000..11de8f9b19 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java @@ -0,0 +1,107 @@ +package net.osmand.plus.quickaction; + + +import android.view.ViewGroup; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +import net.osmand.plus.R; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +public class QuickActionFactory { + + public String quickActionListToString(ArrayList quickActions){ + + String json = new Gson().toJson(quickActions); + return json; + } + + public List parseActiveActionsList(String json) { + + Type type = new TypeToken>(){}.getType(); + ArrayList quickActions = new Gson().fromJson(json, type); + + return quickActions; + } + + public List produceTypeActionsList() { + + ArrayList quickActions = new ArrayList<>(); + + quickActions.add(new MarkerAction()); + quickActions.add(new FavoriteAction()); + + return quickActions; + } + + public QuickAction produceAction(QuickAction quickAction){ + + if (quickAction.id == MarkerAction.ID) { + + return new MarkerAction(quickAction); + + } else if (quickAction.id == FavoriteAction.ID){ + + return new FavoriteAction(quickAction); + + } else return quickAction; + } + + public class MarkerAction extends QuickAction { + + public static final int ID = 1; + + private MarkerAction(){ + id = ID; + nameRes = R.string.quick_action_add_marker; + iconRes = R.drawable.ic_action_flag_dark; + } + + public MarkerAction(QuickAction quickAction) { + super(quickAction); + } + + @Override + public void execute() { + + //TODO do some action + } + + @Override + public void drawUI(ViewGroup parent) { + + //TODO inflate view & fill with params + } + } + + public class FavoriteAction extends QuickAction { + + public static final int ID = 2; + + public FavoriteAction() { + id = ID; + nameRes = R.string.quick_action_add_favorite; + iconRes = R.drawable.ic_action_fav_dark; + } + + public FavoriteAction(QuickAction quickAction) { + super(quickAction); + } + + @Override + public void execute() { + + //TODO do some action + } + + @Override + public void drawUI(ViewGroup parent) { + + //TODO inflate view & fill with params + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java index 08043b70fc..325f9c400a 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java @@ -109,6 +109,19 @@ public class QuickActionListFragment extends BaseOsmAndFragment { toolbar.setTitleTextColor(ContextCompat.getColor(getContext(), R.color.color_white)); } + @Override + public void onResume() { + super.onResume(); + + + } + + @Override + public void onPause() { + super.onPause(); + + } + private List createMockDada() { List result = new ArrayList<>(); for (int i = 0; i < 3; i++) { diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java index b0717cfc8a..d5283d1fea 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java @@ -358,7 +358,7 @@ public class MapWidgetRegistry { public void addControls(MapActivity map, ContextMenuAdapter cm, ApplicationMode mode) { - addQuickActionControl(map, cm, mode); + addQuickActionControl(map, cm); // Right panel cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_right, map) .setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem()); @@ -385,8 +385,7 @@ public class MapWidgetRegistry { return leftWidgetSet; } - private void addQuickActionControl(final MapActivity mapActivity, final ContextMenuAdapter contextMenuAdapter, - final ApplicationMode mode) { + private void addQuickActionControl(final MapActivity mapActivity, final ContextMenuAdapter contextMenuAdapter) { contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_right, mapActivity) .setCategory(true).setLayout(R.layout.list_group_empty_title_with_switch).createItem()); @@ -401,7 +400,7 @@ public class MapWidgetRegistry { .setListener(new ContextMenuAdapter.OnRowItemClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int position, boolean isChecked) { - setVisibility(adapter, position, isChecked, false); + setVisibility(adapter, position, isChecked); return false; } @@ -420,9 +419,8 @@ public class MapWidgetRegistry { private void setVisibility(ArrayAdapter adapter, int position, - boolean visible, - boolean collapsed) { -// MapWidgetRegistry.this.setVisibility(r, visible, collapsed); + boolean visible) { + MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer(); if (mil != null) { mil.recreateControls(); @@ -431,6 +429,8 @@ public class MapWidgetRegistry { item.setSelected(visible); item.setColorRes(visible ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); adapter.notifyDataSetChanged(); + + settings.QUICK_ACTION.set(visible); } }) .createItem()); From 4eebfa6861401a83563538393984a9e6add65692 Mon Sep 17 00:00:00 2001 From: Korusn Oleksandr Date: Thu, 22 Dec 2016 16:47:14 +0200 Subject: [PATCH 11/81] quick action list refactor --- .../osmand/plus/quickaction/QuickAction.java | 4 ++ .../quickaction/QuickActionListFragment.java | 63 ++++++++----------- .../views/mapwidgets/MapWidgetRegistry.java | 2 +- 3 files changed, 31 insertions(+), 38 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java index b8938987a0..b338cd3d6b 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java @@ -33,6 +33,10 @@ public class QuickAction { return iconRes; } + public int getId() { + return id; + } + public HashMap getParams() { return params; } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java index 325f9c400a..5c8b7b72a5 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java @@ -1,7 +1,5 @@ package net.osmand.plus.quickaction; -import android.app.Activity; -import android.content.Context; import android.content.res.Resources; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; @@ -43,6 +41,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment { RecyclerView quickActionRV; FloatingActionButton fab; + QuickActionFactory quickActionFactory = new QuickActionFactory(); QuickActionAdapter adapter; ItemTouchHelper touchHelper; @@ -59,7 +58,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment { fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - adapter.addItem(new QuickActionItem(R.string.map_marker, R.drawable.ic_action_flag_dark)); +// adapter.addItem(new QuickActionItem(R.string.map_marker, R.drawable.ic_action_flag_dark)); } }); @@ -112,39 +111,24 @@ public class QuickActionListFragment extends BaseOsmAndFragment { @Override public void onResume() { super.onResume(); - - + getMapActivity().disableDrawer(); } @Override public void onPause() { super.onPause(); - + getMapActivity().enableDrawer(); } - private List createMockDada() { - List result = new ArrayList<>(); - for (int i = 0; i < 3; i++) { - result.add(new QuickActionItem(R.string.favorite, R.drawable.ic_action_flag_dark)); - result.add(new QuickActionItem(R.string.poi, R.drawable.ic_action_flag_dark)); - result.add(new QuickActionItem(R.string.map_marker, R.drawable.ic_action_flag_dark)); + private List createMockDada() { + List result = new ArrayList<>(); + for (int i = 0; i < 4; i++) { + result.addAll(quickActionFactory.produceTypeActionsList()); } return result; } - @Override - public void onAttach(Context context) { - super.onAttach(context); - getMapActivity().disableDrawer(); - } - - @Override - public void onDetach() { - super.onDetach(); - getMapActivity().enableDrawer(); - } - private MapActivity getMapActivity() { return (MapActivity) getActivity(); } @@ -156,7 +140,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment { private static final int ITEMS_IN_GROUP = 6; - private List itemsList = new ArrayList<>(); + private List itemsList = new ArrayList<>(); private final OnStartDragListener onStartDragListener; public QuickActionAdapter(OnStartDragListener onStartDragListener) { @@ -175,7 +159,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment { @Override public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); - QuickActionItem item = itemsList.get(position); + QuickAction item = itemsList.get(position); if (viewType == SCREEN_ITEM_TYPE) { final QuickActionItemVH itemVH = (QuickActionItemVH) holder; @@ -183,7 +167,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment { itemVH.title.setText(item.getNameRes()); itemVH.subTitle.setText(getResources().getString(R.string.quick_action_item_action, getActionPosition(position))); - itemVH.icon.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(item.getDrawableRes())); + itemVH.icon.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(item.getIconRes())); itemVH.handleView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { @@ -201,8 +185,10 @@ public class QuickActionListFragment extends BaseOsmAndFragment { } }); - LinearLayout.LayoutParams dividerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - dividerParams.setMargins(isShortDivider(position) ? dpToPx(56f) : 0, 0, 0, 0); +// LinearLayout.LayoutParams dividerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + LinearLayout.LayoutParams dividerParams = (LinearLayout.LayoutParams) itemVH.divider.getLayoutParams(); + dividerParams.setMargins(!isLongDivider(position) ? dpToPx(56f) : 0, 0, 0, 0); + itemVH.divider.setLayoutParams(dividerParams); } else { QuickActionHeaderVH headerVH = (QuickActionHeaderVH) holder; headerVH.headerName.setText(getResources().getString(R.string.quick_action_item_screen, position / (ITEMS_IN_GROUP + 1) + 1)); @@ -216,7 +202,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment { @Override public int getItemViewType(int position) { - return itemsList.get(position).isHeader() ? SCREEN_HEADER_TYPE : SCREEN_ITEM_TYPE; + return itemsList.get(position).getId() == 0 ? SCREEN_HEADER_TYPE : SCREEN_ITEM_TYPE; } public void deleteItem(int position) { @@ -253,11 +239,11 @@ public class QuickActionListFragment extends BaseOsmAndFragment { fab.show(); } - public void addItems(List data) { - List resultList = new ArrayList<>(); + public void addItems(List data) { + List resultList = new ArrayList<>(); for (int i = 0; i < data.size(); i++) { if (i % ITEMS_IN_GROUP == 0) - resultList.add(QuickActionItem.createHeaderItem()); + resultList.add(createHeader()); //creates header item resultList.add(data.get(i)); } @@ -266,21 +252,24 @@ public class QuickActionListFragment extends BaseOsmAndFragment { notifyDataSetChanged(); } - public void addItem(QuickActionItem item) { + public void addItem(QuickAction item) { int oldSize = itemsList.size(); if (oldSize % (ITEMS_IN_GROUP + 1) == 0) - itemsList.add(QuickActionItem.createHeaderItem()); + itemsList.add(createHeader()); itemsList.add(item); notifyItemRangeInserted(oldSize, itemsList.size() - oldSize); } + private QuickAction createHeader() { + return new QuickAction(); + } private int getActionPosition(int globalPosition) { return globalPosition % (ITEMS_IN_GROUP + 1); } - private boolean isShortDivider(int globalPosition) { - return getActionPosition(globalPosition) == ITEMS_IN_GROUP || (globalPosition + 1) == getItemCount(); + private boolean isLongDivider(int globalPosition) { + return getActionPosition(globalPosition) == ITEMS_IN_GROUP || globalPosition == getItemCount() - 1; } public boolean isRecyclerScrollable(RecyclerView recyclerView) { diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java index d5283d1fea..2bda11cb8d 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java @@ -390,7 +390,7 @@ public class MapWidgetRegistry { contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_right, mapActivity) .setCategory(true).setLayout(R.layout.list_group_empty_title_with_switch).createItem()); - boolean selected = true; + boolean selected = settings.QUICK_ACTION.get(); contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder() .setTitleId(R.string.configure_screen_quick_action, mapActivity) .setIcon(R.drawable.map_quick_action) From c4ebbb4436c444c05f3a8cd4c18bfe51b38c2194 Mon Sep 17 00:00:00 2001 From: Rosty Date: Thu, 22 Dec 2016 17:43:47 +0200 Subject: [PATCH 12/81] quick action add dialog --- OsmAnd/res/layout/quick_action_add_dialog.xml | 47 +++++++ .../layout/quick_action_add_dialog_item.xml | 31 +++++ OsmAnd/res/values/strings.xml | 3 + OsmAnd/res/values/styles.xml | 6 + .../quickaction/AddQuickActionDialog.java | 126 ++++++++++++++++++ .../plus/quickaction/QuickActionFactory.java | 6 +- .../quickaction/QuickActionListFragment.java | 18 ++- 7 files changed, 233 insertions(+), 4 deletions(-) create mode 100644 OsmAnd/res/layout/quick_action_add_dialog.xml create mode 100644 OsmAnd/res/layout/quick_action_add_dialog_item.xml create mode 100644 OsmAnd/src/net/osmand/plus/quickaction/AddQuickActionDialog.java diff --git a/OsmAnd/res/layout/quick_action_add_dialog.xml b/OsmAnd/res/layout/quick_action_add_dialog.xml new file mode 100644 index 0000000000..556f089eb0 --- /dev/null +++ b/OsmAnd/res/layout/quick_action_add_dialog.xml @@ -0,0 +1,47 @@ + + + + + + + + + +