From 9a156e424fe9882f2c5764c57fbf0e547267d37a Mon Sep 17 00:00:00 2001 From: Denis Date: Mon, 3 Nov 2014 17:15:45 +0200 Subject: [PATCH 1/2] FIxed drawer modes position --- .../activities/actions/AppModeDialog.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java b/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java index 3f01f6803a..3e1eb9536d 100644 --- a/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java +++ b/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java @@ -93,7 +93,7 @@ public class AppModeDialog { private static ToggleButton[] createDrawerToggles(final List visible,final List modes, final Set selected, final Activity a, final LinearLayout ll, final ContextMenuAdapter.BooleanResult allModes, final View.OnClickListener onClickListener) { - ToggleButton[] buttons = createToggles(visible, ll, a); + ToggleButton[] buttons = createToggles(visible, ll, a, true); ToggleButton[] newButtons = new ToggleButton[buttons.length + 1]; for (int i = 0; i < buttons.length; i++) { newButtons[i] = buttons[i]; @@ -141,7 +141,7 @@ public class AppModeDialog { container.setLayoutParams(params); ll.addView(container); } - buttons[i] = createToggle(a, container, allModes.get(i)); + buttons[i] = createToggle(a, container, allModes.get(i), true); } for (int i = 0; i < buttons.length; i++) { setButtonListener(allModes, selected, onClickListener, buttons, i, true); @@ -177,7 +177,7 @@ public class AppModeDialog { public static View prepareAppModeView(Activity a, final List values , final Set selected, ViewGroup parent, final boolean singleSelection, final View.OnClickListener onClickListener) { LinearLayout ll = (LinearLayout) a.getLayoutInflater().inflate(R.layout.mode_toggles, parent); - final ToggleButton[] buttons = createToggles(values, ll, a); + final ToggleButton[] buttons = createToggles(values, ll, a, false); for (int i = 0; i < buttons.length; i++) { setButtonListener(values, selected, onClickListener, buttons, i, singleSelection); } @@ -226,7 +226,7 @@ public class AppModeDialog { } } - static ToggleButton[] createToggles(final List values, LinearLayout topLayout, Context ctx) { + static ToggleButton[] createToggles(final List values, LinearLayout topLayout, Context ctx, boolean drawer) { final ToggleButton[] buttons = new ToggleButton[values.size()]; HorizontalScrollView scroll = new HorizontalScrollView(ctx); @@ -237,13 +237,19 @@ public class AppModeDialog { int k = 0; for(ApplicationMode ma : values) { - buttons[k++] = createToggle(ctx, ll, ma); + buttons[k++] = createToggle(ctx, ll, ma, drawer); } return buttons; } - static private ToggleButton createToggle(Context ctx, LinearLayout layout, ApplicationMode mode){ - int left = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, ctx.getResources().getDisplayMetrics()); + static private ToggleButton createToggle(Context ctx, LinearLayout layout, ApplicationMode mode, boolean drawer){ + int left = 0; + if (drawer) { + left = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, ctx.getResources().getDisplayMetrics()); + } else { + left = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, ctx.getResources().getDisplayMetrics()); + } + int metrics = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 64, ctx.getResources().getDisplayMetrics()); ToggleButton tb = new ToggleButton(ctx); tb.setTextOn(""); From a350247d007db46c1953380dd38b7597ba9a194d Mon Sep 17 00:00:00 2001 From: Denis Date: Mon, 3 Nov 2014 17:53:43 +0200 Subject: [PATCH 2/2] Simplified code --- .../net/osmand/plus/activities/actions/AppModeDialog.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java b/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java index 3e1eb9536d..ebe54e0962 100644 --- a/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java +++ b/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java @@ -243,13 +243,13 @@ public class AppModeDialog { } static private ToggleButton createToggle(Context ctx, LinearLayout layout, ApplicationMode mode, boolean drawer){ - int left = 0; + int margin = 0; if (drawer) { - left = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, ctx.getResources().getDisplayMetrics()); + margin = 5; } else { - left = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, ctx.getResources().getDisplayMetrics()); + margin = 10; } - + int left = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, margin, ctx.getResources().getDisplayMetrics()); int metrics = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 64, ctx.getResources().getDisplayMetrics()); ToggleButton tb = new ToggleButton(ctx); tb.setTextOn("");