From e0b192d5a2f42459246eb76380c07b0f63212722 Mon Sep 17 00:00:00 2001 From: Rosty Date: Fri, 23 Dec 2016 19:13:14 +0200 Subject: [PATCH] auick action widget (tested/buds fixed) --- .../quick_action_controls_background.xml | 8 +++ OsmAnd/res/layout/quick_action_widget.xml | 27 ++++--- OsmAnd/res/layout/quick_action_widget_dot.xml | 2 +- .../res/layout/quick_action_widget_item.xml | 72 ++++++++++++------- .../res/layout/quick_action_widget_page.xml | 13 ++-- OsmAnd/res/values/colors.xml | 1 + .../osmand/plus/activities/MapActivity.java | 3 + .../plus/quickaction/QuickActionFactory.java | 2 +- .../plus/quickaction/QuickActionsWidget.java | 49 +++++++------ .../plus/widgets/WrapContentViewPager.java | 40 ----------- 10 files changed, 105 insertions(+), 112 deletions(-) create mode 100644 OsmAnd/res/drawable/quick_action_controls_background.xml delete mode 100644 OsmAnd/src/net/osmand/plus/widgets/WrapContentViewPager.java diff --git a/OsmAnd/res/drawable/quick_action_controls_background.xml b/OsmAnd/res/drawable/quick_action_controls_background.xml new file mode 100644 index 0000000000..96870ed8ca --- /dev/null +++ b/OsmAnd/res/drawable/quick_action_controls_background.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/quick_action_widget.xml b/OsmAnd/res/layout/quick_action_widget.xml index 91d9c279f6..44fad61397 100644 --- a/OsmAnd/res/layout/quick_action_widget.xml +++ b/OsmAnd/res/layout/quick_action_widget.xml @@ -1,40 +1,39 @@ + android:orientation="vertical" + android:clickable="true"> - + android:layout_height="200dp" /> + android:background="@drawable/quick_action_controls_background" + android:orientation="horizontal"> + android:paddingLeft="16dp" + android:paddingRight="16dp" /> + android:orientation="horizontal" /> + android:paddingRight="16dp" /> diff --git a/OsmAnd/res/layout/quick_action_widget_dot.xml b/OsmAnd/res/layout/quick_action_widget_dot.xml index aa9b608c7c..dbfa02b186 100644 --- a/OsmAnd/res/layout/quick_action_widget_dot.xml +++ b/OsmAnd/res/layout/quick_action_widget_dot.xml @@ -1,6 +1,6 @@ - - - + - + - \ No newline at end of file + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/quick_action_widget_page.xml b/OsmAnd/res/layout/quick_action_widget_page.xml index ed0d148145..83060900da 100644 --- a/OsmAnd/res/layout/quick_action_widget_page.xml +++ b/OsmAnd/res/layout/quick_action_widget_page.xml @@ -1,16 +1,11 @@ + - - - \ No newline at end of file + grid:alignmentMode="alignMargins" + grid:columnCount="3"/> \ No newline at end of file diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index 5247facf0b..ab27a8846c 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -99,6 +99,7 @@ #727272 #ccc + #ff4f4f4f #505050 diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 1671f80532..c121260a36 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -89,6 +89,9 @@ import net.osmand.plus.mapcontextmenu.MapContextMenuFragment; import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu; import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu; import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenuFragment; +import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionFactory; +import net.osmand.plus.quickaction.QuickActionsWidget; import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.routing.RoutingHelper; diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java index 34e80fec22..16f0a92732 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java @@ -20,7 +20,7 @@ public class QuickActionFactory { return json; } - public List parseActiveActionsList(String json) { + public static List parseActiveActionsList(String json) { Type type = new TypeToken>(){}.getType(); ArrayList quickActions = new Gson().fromJson(json, type); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionsWidget.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionsWidget.java index 6b17446641..4f9351fe8e 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionsWidget.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionsWidget.java @@ -109,29 +109,33 @@ public class QuickActionsWidget extends LinearLayout { } }); - dots = (RadioGroup) findViewById(R.id.radioGroup); + dots = (LinearLayout) findViewById(R.id.dots); + dots.removeAllViews(); - if (pageCount > 1) { + if (pageCount > 1) { for (int i = 0; i < pageCount; i++) { ImageView dot = (ImageView) getLayoutInflater() .inflate(R.layout.quick_action_widget_dot, dots, false); - dot.setImageDrawable(getIconsCache().getIcon( - R.drawable.ic_dot_position, R.color.icon_color_light)); + dot.setImageDrawable(i == 0 + ? getIconsCache().getIcon(R.drawable.ic_dot_position, R.color.dashboard_blue) + : getIconsCache().getIcon(R.drawable.ic_dot_position, R.color.icon_color_light)); - dots.addView(new RadioButton(context)); + dots.addView(dot); } } controls = (LinearLayout) findViewById(R.id.controls); controls.setVisibility(pageCount > 1 ? VISIBLE : GONE); + + updateControls(viewPager.getCurrentItem()); } private void updateControls(int position) { - next.setEnabled(viewPager.getAdapter().getCount() > position); + next.setEnabled(viewPager.getAdapter().getCount() > position + 1); next.setImageDrawable(next.isEnabled() ? getIconsCache().getIcon(R.drawable.ic_arrow_forward, R.color.icon_color) : getIconsCache().getIcon(R.drawable.ic_arrow_forward, R.color.icon_color_light)); @@ -141,12 +145,10 @@ public class QuickActionsWidget extends LinearLayout { ? getIconsCache().getIcon(R.drawable.ic_arrow_back, R.color.icon_color) : getIconsCache().getIcon(R.drawable.ic_arrow_back, R.color.icon_color_light)); - dots.removeAllViews(); - for (int i = 0; i < dots.getChildCount(); i++){ ((ImageView) dots.getChildAt(i)).setImageDrawable(i == position - ? getIconsCache().getIcon(R.drawable.ic_dot_position, R.color.icon_color_light) + ? getIconsCache().getIcon(R.drawable.ic_dot_position, R.color.dashboard_blue) : getIconsCache().getIcon(R.drawable.ic_dot_position, R.color.icon_color_light)); } } @@ -154,26 +156,28 @@ public class QuickActionsWidget extends LinearLayout { private View createPageView(ViewGroup container, int position){ LayoutInflater li = getLayoutInflater(); - GridLayout gridLayout = (GridLayout) li - .inflate(R.layout.quick_action_widget_page, container, false); + View page = li.inflate(R.layout.quick_action_widget_page, container, false); + GridLayout gridLayout = (GridLayout) page.findViewById(R.id.grid); - final int maxItems = position > 0 - ? ELEMENT_PER_PAGE - : (actions.size() > (ELEMENT_PER_PAGE / 2) - ? ELEMENT_PER_PAGE - : (ELEMENT_PER_PAGE / 2)); +// final int maxItems = position > 0 +// ? ELEMENT_PER_PAGE +// : (actions.size() > (ELEMENT_PER_PAGE / 2) +// ? ELEMENT_PER_PAGE +// : (ELEMENT_PER_PAGE / 2)); - for (int i = position == 0 ? 0 : 1; i > ELEMENT_PER_PAGE; i++){ + final int maxItems = actions.size() == 1 ? 1 : ELEMENT_PER_PAGE; + + for (int i = 0; i < maxItems; i++){ View view = li.inflate(R.layout.quick_action_widget_item, gridLayout, false); - if (i * (position + 1) < actions.size()) { + if (i + (position * ELEMENT_PER_PAGE) < actions.size()) { - final QuickAction action = actions.get(i * (position + 1)); + final QuickAction action = actions.get(i + (position * ELEMENT_PER_PAGE)); ((ImageView) view.findViewById(R.id.imageView)) .setImageDrawable(getIconsCache() - .getIcon(action.getIconRes(), R.color.icon_color)); + .getIcon(action.getIconRes(), R.color.icon_color_dark)); ((TextView) view.findViewById(R.id.title)) .setText(action.getNameRes()); @@ -187,6 +191,9 @@ public class QuickActionsWidget extends LinearLayout { }); } + view.findViewById(R.id.dividerBot).setVisibility(i < ELEMENT_PER_PAGE / 2 ? VISIBLE : GONE); + view.findViewById(R.id.dividerRight).setVisibility(((i + 1) % 3) == 0 ? GONE : VISIBLE); + gridLayout.addView(view); } @@ -221,7 +228,7 @@ public class QuickActionsWidget extends LinearLayout { } private int countPage(){ - return (int) Math.ceil((actions.size()) / 6); + return (int) Math.ceil((actions.size()) / (double) 6); } private LayoutInflater getLayoutInflater(){ diff --git a/OsmAnd/src/net/osmand/plus/widgets/WrapContentViewPager.java b/OsmAnd/src/net/osmand/plus/widgets/WrapContentViewPager.java deleted file mode 100644 index 9ee5d3f845..0000000000 --- a/OsmAnd/src/net/osmand/plus/widgets/WrapContentViewPager.java +++ /dev/null @@ -1,40 +0,0 @@ -package net.osmand.plus.widgets; - - -import android.content.Context; -import android.support.v4.view.ViewPager; -import android.util.AttributeSet; -import android.view.View; - -public class WrapContentViewPager extends ViewPager { - - private int mCurrentPagePosition = 0; - - public WrapContentViewPager(Context context) { - super(context); - } - - public WrapContentViewPager(Context context, AttributeSet attrs) { - super(context, attrs); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - try { - View child = getChildAt(mCurrentPagePosition); - if (child != null) { - child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); - int h = child.getMeasuredHeight(); - heightMeasureSpec = MeasureSpec.makeMeasureSpec(h, MeasureSpec.EXACTLY); - } - } catch (Exception e) { - e.printStackTrace(); - } - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - } - - public void reMeasureCurrentPage(int position) { - mCurrentPagePosition = position; - requestLayout(); - } -}