From be66d43e4c77c295c2df1f304cb834373093b864 Mon Sep 17 00:00:00 2001 From: Phillip Hsu Date: Fri, 26 Aug 2016 23:27:45 -0700 Subject: [PATCH] Minute selection indicator restored on rotate --- .../clock2/editalarm/MinutesGrid.java | 28 ++++++++----------- .../clock2/editalarm/NumbersGrid.java | 15 +++++----- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/com/philliphsu/clock2/editalarm/MinutesGrid.java b/app/src/main/java/com/philliphsu/clock2/editalarm/MinutesGrid.java index d1238e1..b08fe08 100644 --- a/app/src/main/java/com/philliphsu/clock2/editalarm/MinutesGrid.java +++ b/app/src/main/java/com/philliphsu/clock2/editalarm/MinutesGrid.java @@ -28,7 +28,6 @@ public class MinutesGrid extends NumbersGrid { int value = getSelection() - 1; if (value < 0) value = 59; - setIndicator(value); // TODO: Remove when you move this logic to setSelection() setSelection(value); mSelectionListener.onNumberSelected(value); } @@ -39,13 +38,24 @@ public class MinutesGrid extends NumbersGrid { int value = getSelection() + 1; if (value == 60) value = 0; - setIndicator(value); // TODO: Remove when you move this logic to setSelection() setSelection(value); mSelectionListener.onNumberSelected(value); } }); } + @Override + public void setSelection(int value) { + super.setSelection(value); + if (value % 5 == 0) { + // The new value is one of the predetermined minute values + int positionOfValue = value / 5; + setIndicator(getChildAt(positionOfValue)); + } else { + clearIndicator(); + } + } + @Override protected int contentLayout() { return R.layout.content_minutes_grid; @@ -70,18 +80,4 @@ public class MinutesGrid extends NumbersGrid { context, R.drawable.ic_add_circle_24dp, colorActiveLight)); } } - - /** - * Helper method for minute tuners to set the indicator. - * @param value the new value set by the minute tuners - */ - // TODO: Move this logic to setSelection() - private void setIndicator(int value) { - clearIndicator(); // TODO: Remove? - if (value % 5 == 0) { - // The new value is one of the predetermined minute values - int positionOfValue = value / 5; - setIndicator(getChildAt(positionOfValue)); - } - } } diff --git a/app/src/main/java/com/philliphsu/clock2/editalarm/NumbersGrid.java b/app/src/main/java/com/philliphsu/clock2/editalarm/NumbersGrid.java index 1df8f95..fd483a3 100644 --- a/app/src/main/java/com/philliphsu/clock2/editalarm/NumbersGrid.java +++ b/app/src/main/java/com/philliphsu/clock2/editalarm/NumbersGrid.java @@ -132,6 +132,14 @@ public abstract class NumbersGrid extends GridLayout implements View.OnClickList return 0; } + /** + * @return the number held by the button parsed into an integer. The base implementation + * assumes the view is of type TextView. + */ + protected int valueOf(View button) { + return Integer.parseInt(((TextView) button).getText().toString()); + } + /** * The default implementation sets the appropriate text color on all of the number buttons * as determined by {@link #canRegisterClickListener(View)}. @@ -167,11 +175,4 @@ public abstract class NumbersGrid extends GridLayout implements View.OnClickList i++; } } - - /** - * Parses the number held by the button into an integer. - */ - private static int valueOf(View button) { - return Integer.parseInt(((TextView) button).getText().toString()); - } }