diff --git a/README.md b/README.md index dbc1e595..26c923fc 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ The **mainLayout** is the root view you want the visualizations to be shown. To display a numeric value use the code snippet below. ```Java - NumericDisplayModel indicator1 = getIndicatorDisplayModel(TOTAL_COUNT, ChartUtil.numericIndicatorKey, R.string.total_under_5_count, indicatorTallies); + NumericIndicatorDisplayOptions indicator1 = getNumericIndicatorDisplayOptions(TOTAL_COUNT, ChartUtil.numericIndicatorKey, R.string.total_under_5_count, indicatorTallies); mainLayout.addView(new NumericIndicatorView(getContext(), indicator1).createView()); ``` @@ -43,7 +43,7 @@ For pie charts display. You can use the following code snippet. ```Java PieChartSlice indicator2_1 = getPieChartSlice(LATEST_COUNT, ChartUtil.pieChartYesIndicatorKey, getResources().getString(R.string.yes_slice_label), getResources().getColor(R.color.colorPieChartGreen), indicatorTallies); PieChartSlice indicator2_2 = getPieChartSlice(LATEST_COUNT, ChartUtil.pieChartNoIndicatorKey, getResources().getString(R.string.no_button_label), getResources().getColor(R.color.colorPieChartRed), indicatorTallies); - mainLayout.addView(new PieChartIndicatorView(getContext(), getPieChartDisplayModel(addPieChartSlices(indicator2_1, indicator2_2), R.string.num_of_lieterate_children_0_60_label, R.string.sample_note)).createView()); + mainLayout.addView(new PieChartIndicatorView(getContext(), getPieChartDisplayOptions(addPieChartSlices(indicator2_1, indicator2_2), R.string.num_of_lieterate_children_0_60_label, R.string.sample_note, null)).createView()); ``` ### Progress indicator This indicator widget basically has a progressbar, main title(Label) and a sub title. @@ -67,7 +67,7 @@ using the property **progressDrawable** listed above, you can set the progressDr **Programmatically:** ``` - ProgressIndicatorView progressWidget = getActivity().findViewById(R.id.progressIndicatorView); + ProgressIndicator progressWidget = getActivity().findViewById(R.id.progressIndicatorView); progressWidget.setProgress(42); progressWidget.setTitle("Users registered - 42%"); progressWidget.setProgressDrawable(R.drawable.progress_indicator_bg); @@ -78,7 +78,7 @@ using the property **progressDrawable** listed above, you can set the progressDr **Via XML:** ``` - slices; private PieChartSelectListener listener; - public PieChartIndicatorData(boolean hasLabels, boolean hasLabelsOutside, boolean hasCenterCircle, List slices) { + public PieChartConfig(boolean hasLabels, boolean hasLabelsOutside, boolean hasCenterCircle, List slices) { this.hasLabels = hasLabels; this.hasLabelsOutside = hasLabelsOutside; this.hasCenterCircle = hasCenterCircle; this.slices = slices; } - public PieChartIndicatorData() {} + public PieChartConfig() {} public boolean hasLabels() { return hasLabels; diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/PieChartIndicatorVisualization.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/PieChartIndicatorDisplayOptions.java similarity index 54% rename from opensrp-reporting/src/main/java/org/smartregister/reporting/domain/PieChartIndicatorVisualization.java rename to opensrp-reporting/src/main/java/org/smartregister/reporting/domain/PieChartIndicatorDisplayOptions.java index 016fdd40..218787cd 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/PieChartIndicatorVisualization.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/PieChartIndicatorDisplayOptions.java @@ -4,29 +4,20 @@ import java.util.List; -/** - * PieChartIndicatorVisualization is the base class for indicator visualizations that display - * pie chart data - * The pie chart indicator visualization consists the indicator label (text description) and the chart data that - * defines configuration of the chart that is to be displayed - * - * @author allan - */ +public class PieChartIndicatorDisplayOptions extends ReportingIndicatorDisplayOptions { -public class PieChartIndicatorVisualization extends ReportingIndicatorVisualization { + private PieChartConfig pieChartConfig; - private PieChartIndicatorData chartData; - - public PieChartIndicatorVisualization(PieChartIndicatorData chartData) { - this.chartData = chartData; + public PieChartIndicatorDisplayOptions(PieChartConfig pieChartConfig) { + this.pieChartConfig = pieChartConfig; } - public PieChartIndicatorData getChartData() { - return chartData; + public PieChartConfig getPieChartConfig() { + return pieChartConfig; } - public void setChartData(PieChartIndicatorData chartData) { - this.chartData = chartData; + public void setPieChartConfig(PieChartConfig pieChartConfig) { + this.pieChartConfig = pieChartConfig; } public static class PieChartIndicatorVisualizationBuilder { @@ -74,17 +65,17 @@ public PieChartIndicatorVisualizationBuilder chartListener(PieChartSelectListene return this; } - public PieChartIndicatorVisualization build() { - PieChartIndicatorData chartData = new PieChartIndicatorData(); - chartData.setHasLabels(this.hasLabels); - chartData.setHasLabelsOutside(this.hasLabelsOutside); - chartData.setHasCenterCircle(this.hasCenterCircle); - chartData.setSlices(this.slices); - chartData.setListener(this.listener); - PieChartIndicatorVisualization pieChartIndicatorVisualization = new PieChartIndicatorVisualization(chartData); - pieChartIndicatorVisualization.setIndicatorLabel(this.indicatorLabel); - pieChartIndicatorVisualization.setIndicatorNote(this.indicatorNote); - return pieChartIndicatorVisualization; + public PieChartIndicatorDisplayOptions build() { + PieChartConfig chartConfig = new PieChartConfig(); + chartConfig.setHasLabels(this.hasLabels); + chartConfig.setHasLabelsOutside(this.hasLabelsOutside); + chartConfig.setHasCenterCircle(this.hasCenterCircle); + chartConfig.setSlices(this.slices); + chartConfig.setListener(this.listener); + PieChartIndicatorDisplayOptions pieChartIndicatorDisplayOptions = new PieChartIndicatorDisplayOptions(chartConfig); + pieChartIndicatorDisplayOptions.setIndicatorLabel(this.indicatorLabel); + pieChartIndicatorDisplayOptions.setIndicatorNote(this.indicatorNote); + return pieChartIndicatorDisplayOptions; } } diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorConfig.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorConfig.java new file mode 100644 index 00000000..8467a06c --- /dev/null +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorConfig.java @@ -0,0 +1,68 @@ +package org.smartregister.reporting.domain; + +public class ProgressIndicatorConfig { + + private int progressVal; + private String indicatorLabel; + private String progressIndicatorTitle; + private String progressIndicatorSubtitle; + private int progressIndicatorTitleColor; + private int foregroundColor; + private int backgroundColor; + + public int getProgressVal() { + return progressVal; + } + + public void setProgressVal(int progressVal) { + this.progressVal = progressVal; + } + + public String getIndicatorLabel() { + return indicatorLabel; + } + + public void setIndicatorLabel(String indicatorLabel) { + this.indicatorLabel = indicatorLabel; + } + + public String getProgressIndicatorTitle() { + return progressIndicatorTitle; + } + + public void setProgressIndicatorTitle(String progressIndicatorTitle) { + this.progressIndicatorTitle = progressIndicatorTitle; + } + + public String getProgressIndicatorSubtitle() { + return progressIndicatorSubtitle; + } + + public void setProgressIndicatorSubtitle(String progressIndicatorSubtitle) { + this.progressIndicatorSubtitle = progressIndicatorSubtitle; + } + + public int getProgressIndicatorTitleColor() { + return progressIndicatorTitleColor; + } + + public void setProgressIndicatorTitleColor(int progressIndicatorTitleColor) { + this.progressIndicatorTitleColor = progressIndicatorTitleColor; + } + + public int getForegroundColor() { + return foregroundColor; + } + + public void setForegroundColor(int foregroundColor) { + this.foregroundColor = foregroundColor; + } + + public int getBackgroundColor() { + return backgroundColor; + } + + public void setBackgroundColor(int backgroundColor) { + this.backgroundColor = backgroundColor; + } +} diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorDisplayOptions.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorDisplayOptions.java new file mode 100644 index 00000000..f27f0fc1 --- /dev/null +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorDisplayOptions.java @@ -0,0 +1,77 @@ +package org.smartregister.reporting.domain; + + +public class ProgressIndicatorDisplayOptions extends ReportingIndicatorDisplayOptions { + + private ProgressIndicatorConfig config; + + + public ProgressIndicatorDisplayOptions(ProgressIndicatorConfig progressIndicatorConfig) { + this.config = progressIndicatorConfig; + } + + public ProgressIndicatorConfig getConfig() { + return config; + } + + public void setConfig(ProgressIndicatorConfig config) { + this.config = config; + } + + public static class ProgressIndicatorBuilder { + private int progressVal; + private String indicatorLabel; + private String progressIndicatorTitle; + private String progressIndicatorSubtitle; + private int progressIndicatorTitleColor; + private int foregroundColor; + private int backgroundColor; + + public ProgressIndicatorBuilder withProgressValue(int value) { + this.progressVal = value; + return this; + } + + public ProgressIndicatorBuilder withIndicatorLabel(String indicatorLabel) { + this.indicatorLabel = indicatorLabel; + return this; + } + + public ProgressIndicatorBuilder withProgressIndicatorTitle(String title) { + this.progressIndicatorTitle = title; + return this; + } + + public ProgressIndicatorBuilder withProgressIndicatorSubtitle(String subtitle) { + this.progressIndicatorSubtitle = subtitle; + return this; + } + + public ProgressIndicatorBuilder withProgressIndicatorTitleColor(int titleColor) { + this.progressIndicatorTitleColor = titleColor; + return this; + } + + public ProgressIndicatorBuilder withForegroundColor(int foregroundColor) { + this.foregroundColor = foregroundColor; + return this; + } + + public ProgressIndicatorBuilder withBackgroundColor(int backgroundColor) { + this.backgroundColor = backgroundColor; + return this; + } + + public ProgressIndicatorDisplayOptions build() { + ProgressIndicatorConfig config = new ProgressIndicatorConfig(); + config.setProgressVal(this.progressVal); + config.setIndicatorLabel(this.indicatorLabel); + config.setProgressIndicatorTitle(this.progressIndicatorTitle); + config.setProgressIndicatorTitleColor(this.progressIndicatorTitleColor); + config.setProgressIndicatorSubtitle(this.progressIndicatorSubtitle); + config.setForegroundColor(this.foregroundColor); + config.setBackgroundColor(this.backgroundColor); + return new ProgressIndicatorDisplayOptions(config); + } + } +} diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ReportingIndicatorVisualization.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ReportingIndicatorDisplayOptions.java similarity index 75% rename from opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ReportingIndicatorVisualization.java rename to opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ReportingIndicatorDisplayOptions.java index 4c08e86d..e6365c1d 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ReportingIndicatorVisualization.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ReportingIndicatorDisplayOptions.java @@ -1,7 +1,7 @@ package org.smartregister.reporting.domain; /** - * The ReportingIndicatorVisualization base class models reporting indicator visualizations with + * The ReportingIndicatorDisplay base class models reporting indicator visualizations with * common properties. * For instance, the different visualizations will always have a label (description) * of the specific chart. @@ -10,14 +10,14 @@ * @author allan */ -public class ReportingIndicatorVisualization { +public class ReportingIndicatorDisplayOptions { private String indicatorLabel; private String indicatorNote; - public ReportingIndicatorVisualization() { + public ReportingIndicatorDisplayOptions() { } - public ReportingIndicatorVisualization(String indicatorLabel) { + public ReportingIndicatorDisplayOptions(String indicatorLabel) { this.indicatorLabel = indicatorLabel; } diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/IndicatorVisualisationFactory.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/IndicatorVisualisationFactory.java index 3d64485a..c39ce483 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/IndicatorVisualisationFactory.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/IndicatorVisualisationFactory.java @@ -3,8 +3,8 @@ import android.content.Context; import android.view.View; -import org.smartregister.reporting.domain.ReportingIndicatorVisualization; +import org.smartregister.reporting.domain.ReportingIndicatorDisplayOptions; public interface IndicatorVisualisationFactory { - View getIndicatorView(ReportingIndicatorVisualization data, Context context); + View getIndicatorView(ReportingIndicatorDisplayOptions displayOptions, Context context); } diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/NumericDisplayFactory.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/NumericDisplayFactory.java index 5e0e8e36..116cd737 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/NumericDisplayFactory.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/NumericDisplayFactory.java @@ -6,8 +6,8 @@ import android.widget.TextView; import org.smartregister.reporting.R; -import org.smartregister.reporting.domain.NumericIndicatorVisualization; -import org.smartregister.reporting.domain.ReportingIndicatorVisualization; +import org.smartregister.reporting.domain.NumericIndicatorDisplayOptions; +import org.smartregister.reporting.domain.ReportingIndicatorDisplayOptions; import org.smartregister.reporting.util.ReportingUtil; /** @@ -18,18 +18,17 @@ public class NumericDisplayFactory implements IndicatorVisualisationFactory { @Override - public View getIndicatorView(ReportingIndicatorVisualization data, Context context) { - NumericIndicatorVisualization indicatorData = (NumericIndicatorVisualization) data; + public View getIndicatorView(ReportingIndicatorDisplayOptions displayOptions, Context context) { + NumericIndicatorDisplayOptions numericIndicatorDisplay = (NumericIndicatorDisplayOptions) displayOptions; View rootLayout = LayoutInflater.from(context).inflate(R.layout.numeric_indicator_view, null); TextView chartLabelTextView = rootLayout.findViewById(R.id.numeric_indicator_label); + chartLabelTextView.setText(numericIndicatorDisplay.getIndicatorLabel()); TextView chartValueTextView = rootLayout.findViewById(R.id.numeric_indicator_value); - chartLabelTextView.setText(indicatorData.getIndicatorLabel()); - // Only show the required decimal points - chartValueTextView.setText(ReportingUtil.formatDecimal(indicatorData.getValue())); + chartValueTextView.setText(ReportingUtil.formatDecimal(numericIndicatorDisplay.getValue())); return rootLayout; } -} +} \ No newline at end of file diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/PieChartFactory.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/PieChartFactory.java index bb2bb315..f1dae027 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/PieChartFactory.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/PieChartFactory.java @@ -7,11 +7,11 @@ import android.widget.TextView; import org.smartregister.reporting.R; -import org.smartregister.reporting.domain.PieChartIndicatorData; -import org.smartregister.reporting.domain.PieChartIndicatorVisualization; +import org.smartregister.reporting.domain.PieChartConfig; +import org.smartregister.reporting.domain.PieChartIndicatorDisplayOptions; import org.smartregister.reporting.domain.PieChartSlice; import org.smartregister.reporting.domain.PieSliceValue; -import org.smartregister.reporting.domain.ReportingIndicatorVisualization; +import org.smartregister.reporting.domain.ReportingIndicatorDisplayOptions; import org.smartregister.reporting.listener.PieChartSelectListener; import java.util.ArrayList; @@ -30,19 +30,19 @@ public class PieChartFactory implements IndicatorVisualisationFactory { @Override - public View getIndicatorView(ReportingIndicatorVisualization visualization, Context context) { + public View getIndicatorView(ReportingIndicatorDisplayOptions displayOptions, Context context) { LinearLayout rootLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.pie_chart_view, null); TextView chartLabelTextView = rootLayout.findViewById(R.id.pie_indicator_label); TextView chartNoteTextView = rootLayout.findViewById(R.id.pie_note_label); TextView numericValueTextView = rootLayout.findViewById(R.id.numeric_indicator_value); - PieChartIndicatorVisualization indicatorVisualization = (PieChartIndicatorVisualization) visualization; - PieChartIndicatorData chartConfiguration = indicatorVisualization.getChartData(); + PieChartIndicatorDisplayOptions pieChartIndicatorDisplayOptions = (PieChartIndicatorDisplayOptions) displayOptions; + PieChartConfig chartConfiguration = pieChartIndicatorDisplayOptions.getPieChartConfig(); - chartLabelTextView.setText(indicatorVisualization.getIndicatorLabel()); - if (indicatorVisualization.getIndicatorNote() != null) { - chartNoteTextView.setText(indicatorVisualization.getIndicatorNote()); + chartLabelTextView.setText(pieChartIndicatorDisplayOptions.getIndicatorLabel()); + if (pieChartIndicatorDisplayOptions.getIndicatorNote() != null) { + chartNoteTextView.setText(pieChartIndicatorDisplayOptions.getIndicatorNote()); } else { // Nothing to show chartNoteTextView.setVisibility(View.GONE); diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/ProgressIndicatorFactory.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/ProgressIndicatorFactory.java new file mode 100644 index 00000000..b439fbb2 --- /dev/null +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/ProgressIndicatorFactory.java @@ -0,0 +1,36 @@ +package org.smartregister.reporting.factory; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.TextView; + +import org.apache.commons.lang3.StringUtils; +import org.smartregister.reporting.R; +import org.smartregister.reporting.domain.ProgressIndicatorConfig; +import org.smartregister.reporting.domain.ProgressIndicatorDisplayOptions; +import org.smartregister.reporting.domain.ReportingIndicatorDisplayOptions; +import org.smartregister.reporting.view.ProgressIndicator; + +public class ProgressIndicatorFactory implements IndicatorVisualisationFactory { + @Override + public View getIndicatorView(ReportingIndicatorDisplayOptions displayOptions, Context context) { + ProgressIndicatorConfig config = ((ProgressIndicatorDisplayOptions) displayOptions).getConfig(); + LinearLayout rootLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.progress_indicator_factory_layout, null); + + TextView indicatorLabel = rootLayout.findViewById(R.id.tv_indicator_label); + String label = StringUtils.isNotBlank(config.getIndicatorLabel()) ? config.getIndicatorLabel() : ""; + indicatorLabel.setText(label); + + ProgressIndicator progressWidget = rootLayout.findViewById(R.id.progressIndicatorView); + progressWidget.setTitle(config.getProgressIndicatorTitle()); + progressWidget.setProgressBarTitleColor(config.getProgressIndicatorTitleColor()); + progressWidget.setSubTitle(config.getProgressIndicatorSubtitle()); + progressWidget.setProgress(config.getProgressVal()); + progressWidget.setProgressBarForegroundColor(config.getForegroundColor()); + progressWidget.setProgressBarBackgroundColor(config.getBackgroundColor()); + + return rootLayout; + } +} diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/BaseReportIndicatorsModel.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/model/BaseReportIndicatorsModel.java similarity index 83% rename from opensrp-reporting/src/main/java/org/smartregister/reporting/domain/BaseReportIndicatorsModel.java rename to opensrp-reporting/src/main/java/org/smartregister/reporting/model/BaseReportIndicatorsModel.java index 420f4605..b96c43a3 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/BaseReportIndicatorsModel.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/model/BaseReportIndicatorsModel.java @@ -1,8 +1,11 @@ -package org.smartregister.reporting.domain; +package org.smartregister.reporting.model; import org.smartregister.reporting.ReportingLibrary; import org.smartregister.reporting.contract.ReportContract; import org.smartregister.reporting.dao.ReportIndicatorDaoImpl; +import org.smartregister.reporting.domain.IndicatorQuery; +import org.smartregister.reporting.domain.IndicatorTally; +import org.smartregister.reporting.domain.ReportIndicator; import java.util.List; import java.util.Map; diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/model/NumericDisplayModel.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/model/NumericDisplayModel.java deleted file mode 100644 index 0051f7d3..00000000 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/model/NumericDisplayModel.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.smartregister.reporting.model; - - -import org.smartregister.reporting.contract.ReportContract; - -public class NumericDisplayModel { - - private ReportContract.IndicatorView.CountType countType; - private String indicatorCode; - private int labelStringResource; - private float count; - - public NumericDisplayModel(ReportContract.IndicatorView.CountType countType, String indicatorCode, int labelStringResource, float count) { - this.countType = countType; - this.indicatorCode = indicatorCode; - this.labelStringResource = labelStringResource; - this.count = count; - } - - public ReportContract.IndicatorView.CountType getCountType() { - return countType; - } - - public String getIndicatorCode() { - return indicatorCode; - } - - public int getLabelStringResource() { - return labelStringResource; - } - - public float getCount() { - return count; - } - - public void setCount(int count) { - this.count = count; - } -} diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/model/PieChartDisplayModel.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/model/PieChartDisplayModel.java deleted file mode 100644 index 2d389d15..00000000 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/model/PieChartDisplayModel.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.smartregister.reporting.model; - -import org.smartregister.reporting.domain.PieChartSlice; -import org.smartregister.reporting.listener.PieChartSelectListener; - -import java.util.List; - -public class PieChartDisplayModel { - private List pieChartSlices; - private Integer indicatorLabel; - private Integer indicatorNote; - private PieChartSelectListener pieChartSelectListener; - - - public PieChartDisplayModel(List pieChartSlices, Integer indicatorLabel, Integer indicatorNote, PieChartSelectListener pieChartSelectListener) { - this.pieChartSlices = pieChartSlices; - this.indicatorLabel = indicatorLabel; - this.indicatorNote = indicatorNote; - this.pieChartSelectListener = pieChartSelectListener; - } - - public Integer getIndicatorNote() { - return indicatorNote; - } - - public Integer getIndicatorLabel() { - return indicatorLabel; - } - - public List getPieChartSlices() { - return pieChartSlices; - } - - public void setPieChartSlices(List pieChartSlices) { - this.pieChartSlices = pieChartSlices; - } - - public PieChartSelectListener getPieChartSelectListener() { - return pieChartSelectListener; - } - - public void setPieChartSelectListener(PieChartSelectListener pieChartSelectListener) { - this.pieChartSelectListener = pieChartSelectListener; - } -} diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java index 92c7099e..743c89a7 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java @@ -6,12 +6,12 @@ import org.smartregister.reporting.contract.ReportContract.IndicatorView.CountType; import org.smartregister.reporting.domain.IndicatorTally; +import org.smartregister.reporting.domain.NumericIndicatorDisplayOptions; +import org.smartregister.reporting.domain.PieChartIndicatorDisplayOptions; import org.smartregister.reporting.domain.PieChartSlice; -import org.smartregister.reporting.domain.ReportingIndicatorVisualization; +import org.smartregister.reporting.domain.ReportingIndicatorDisplayOptions; import org.smartregister.reporting.factory.IndicatorVisualisationFactory; import org.smartregister.reporting.listener.PieChartSelectListener; -import org.smartregister.reporting.model.NumericDisplayModel; -import org.smartregister.reporting.model.PieChartDisplayModel; import java.io.InputStream; import java.text.DecimalFormat; @@ -35,17 +35,17 @@ public static float getLatestCountBasedOnDate(List> return getLatestIndicatorCount(indicatorTallies, indicatorKey); } - public static View getIndicatorView(ReportingIndicatorVisualization reportingIndicatorVisualization, + public static View getIndicatorView(ReportingIndicatorDisplayOptions displayOptions, IndicatorVisualisationFactory visualisationFactory, Context context) { - return visualisationFactory.getIndicatorView(reportingIndicatorVisualization, context); + return visualisationFactory.getIndicatorView(displayOptions, context); } - public static NumericDisplayModel getIndicatorDisplayModel(CountType countType, String indicatorCode, - int labelResource, List> indicatorTallies) { - return new NumericDisplayModel(countType, indicatorCode, labelResource, getCount(countType, indicatorCode, indicatorTallies)); + public static NumericIndicatorDisplayOptions getNumericIndicatorDisplayOptions(CountType countType, String indicatorCode, + String label, List> indicatorTallies) { + return new NumericIndicatorDisplayOptions(label, getCount(countType, indicatorCode, indicatorTallies)); } - private static float getCount(CountType countType, String indicatorCode, List> indicatorTallies) { + public static float getCount(CountType countType, String indicatorCode, List> indicatorTallies) { float count = 0; if (countType == CountType.TOTAL_COUNT) { count = getTotalCount(indicatorTallies, indicatorCode); @@ -55,19 +55,26 @@ private static float getCount(CountType countType, String indicatorCode, List pieChartSlices, - Integer indicatorLabel, Integer indicatorNote, PieChartSelectListener pieChartSelectListener) { - return new PieChartDisplayModel(pieChartSlices, indicatorLabel, indicatorNote, pieChartSelectListener); + public static PieChartIndicatorDisplayOptions getPieChartDisplayOptions(List pieChartSlices, + String indicatorLabel, String indicatorNote, PieChartSelectListener pieChartSelectListener) { + return new PieChartIndicatorDisplayOptions.PieChartIndicatorVisualizationBuilder() + .indicatorLabel(indicatorLabel) + .indicatorNote(indicatorNote) + .chartHasLabels(true) + .chartHasLabelsOutside(true) + .chartHasCenterCircle(false) + .chartSlices(pieChartSlices) + .chartListener(pieChartSelectListener).build(); } public static PieChartSlice getPieChartSlice(CountType countType, String indicatorCode, String label, int color, List> indicatorTallies, String key) { - return new PieChartSlice((float) getCount(countType, indicatorCode, indicatorTallies), label, color, key); + return new PieChartSlice(getCount(countType, indicatorCode, indicatorTallies), label, color, key); } public static PieChartSlice getPieChartSlice(CountType countType, String indicatorCode, String label, int color, List> indicatorTallies) { - return new PieChartSlice((float) getCount(countType, indicatorCode, indicatorTallies), label, color, indicatorCode); + return new PieChartSlice(getCount(countType, indicatorCode, indicatorTallies), label, color, indicatorCode); } public static List addPieChartSlices(PieChartSlice... chartSlices) { @@ -90,7 +97,7 @@ public static AppProperties getProperties(Context context) { } /** - * Formats a double to a maximum of two decimal places or min of an integer representation eg. 2.457, 3.2, 189 + * Formats a double to a maximum of two decimal places or min of an integer representation eg. 2.457, 3.2, 189 */ public static String formatDecimal(double no) { DecimalFormat twoDForm = new DecimalFormat("0.###"); diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/NumericIndicatorView.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/NumericIndicatorView.java index 1360b2a2..272afe07 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/NumericIndicatorView.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/NumericIndicatorView.java @@ -4,32 +4,25 @@ import android.view.View; import org.smartregister.reporting.contract.ReportContract; -import org.smartregister.reporting.domain.NumericIndicatorVisualization; +import org.smartregister.reporting.domain.NumericIndicatorDisplayOptions; import org.smartregister.reporting.factory.NumericDisplayFactory; -import org.smartregister.reporting.model.NumericDisplayModel; - -import static org.smartregister.reporting.util.ReportingUtil.getIndicatorView; +import org.smartregister.reporting.util.ReportingUtil; public class NumericIndicatorView implements ReportContract.IndicatorView { private Context context; - private NumericDisplayModel numericDisplayModel; + private NumericIndicatorDisplayOptions displayOptions; private NumericDisplayFactory numericDisplayFactory; - public NumericIndicatorView(Context context, NumericDisplayModel numericDisplayModel) { + public NumericIndicatorView(Context context, NumericIndicatorDisplayOptions displayOptions) { this.context = context; - this.numericDisplayModel = numericDisplayModel; + this.displayOptions = displayOptions; numericDisplayFactory = new NumericDisplayFactory(); } @Override public View createView() { - return getIndicatorView(getNumericVisualization(), numericDisplayFactory, context); - } - - private NumericIndicatorVisualization getNumericVisualization() { - return new NumericIndicatorVisualization(context.getResources().getString( - numericDisplayModel.getLabelStringResource()), numericDisplayModel.getCount()); + return ReportingUtil.getIndicatorView(displayOptions, numericDisplayFactory, context); } } diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/PieChartIndicatorView.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/PieChartIndicatorView.java index a884c121..413e3a75 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/PieChartIndicatorView.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/PieChartIndicatorView.java @@ -6,69 +6,48 @@ import org.jetbrains.annotations.Nullable; import org.smartregister.reporting.contract.ReportContract; -import org.smartregister.reporting.domain.PieChartIndicatorVisualization; +import org.smartregister.reporting.domain.PieChartIndicatorDisplayOptions; import org.smartregister.reporting.domain.PieChartSlice; import org.smartregister.reporting.factory.PieChartFactory; import org.smartregister.reporting.listener.PieChartSelectListener; -import org.smartregister.reporting.model.PieChartDisplayModel; +import org.smartregister.reporting.util.ReportingUtil; import timber.log.Timber; -import static org.smartregister.reporting.util.ReportingUtil.getIndicatorView; public class PieChartIndicatorView implements ReportContract.IndicatorView { private Context context; private PieChartFactory pieChartFactory; - private PieChartDisplayModel pieChartDisplayModel; + private PieChartIndicatorDisplayOptions displayOptions; - public PieChartIndicatorView(Context context, PieChartDisplayModel pieChartDisplayModel) { + public PieChartIndicatorView(Context context, PieChartIndicatorDisplayOptions displayOptions) { pieChartFactory = new PieChartFactory(); - this.pieChartDisplayModel = pieChartDisplayModel; + this.displayOptions = displayOptions; this.context = context; } /** * Generating a pie chart is memory intensive in lower end devices. * Allow @java.lang.OutOfMemoryError is recorded in some devices + * * @return view */ @Override @Nullable public View createView() { try { - PieChartIndicatorVisualization pieChartIndicatorVisualization = getPieChartVisualization(); - - if (pieChartDisplayModel.getIndicatorLabel() != null) { - pieChartIndicatorVisualization.setIndicatorLabel(context.getResources().getString(pieChartDisplayModel.getIndicatorLabel())); - } - - if (pieChartDisplayModel.getIndicatorNote() != null) { - pieChartIndicatorVisualization.setIndicatorNote(context.getResources().getString(pieChartDisplayModel.getIndicatorNote())); + if (displayOptions.getPieChartConfig().getListener() == null) { + displayOptions.getPieChartConfig().setListener(new ChartListener()); } - return getIndicatorView(pieChartIndicatorVisualization, pieChartFactory, context); - }catch (OutOfMemoryError e){ + return ReportingUtil.getIndicatorView(displayOptions, pieChartFactory, context); + } catch (OutOfMemoryError e) { Timber.e(e); } return null; } - private PieChartIndicatorVisualization getPieChartVisualization() { - // Build the chart - String pieChartLabel = "No label provided"; //to avoid crash when string resource not provide - if (pieChartDisplayModel.getIndicatorLabel() != null) { - pieChartLabel = context.getResources().getString(pieChartDisplayModel.getIndicatorLabel()); - } - return new PieChartIndicatorVisualization.PieChartIndicatorVisualizationBuilder() - .indicatorLabel(pieChartLabel) - .chartHasLabels(true) - .chartHasLabelsOutside(true) - .chartHasCenterCircle(false) - .chartSlices(pieChartDisplayModel.getPieChartSlices()) - .chartListener(pieChartDisplayModel.getPieChartSelectListener() == null ? new ChartListener() : pieChartDisplayModel.getPieChartSelectListener()).build(); - } - public class ChartListener implements PieChartSelectListener { @Override public void handleOnSelectEvent(PieChartSlice slice) { diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/ProgressIndicator.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/ProgressIndicator.java new file mode 100644 index 00000000..2a4588aa --- /dev/null +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/ProgressIndicator.java @@ -0,0 +1,335 @@ +package org.smartregister.reporting.view; + +import android.annotation.TargetApi; +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.PorterDuff; +import android.graphics.drawable.ClipDrawable; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.GradientDrawable; +import android.graphics.drawable.LayerDrawable; +import android.os.Build; +import android.os.Bundle; +import android.os.Parcelable; +import android.text.TextUtils; +import android.util.AttributeSet; +import android.view.Gravity; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.ProgressBar; +import android.widget.TextView; + +import androidx.annotation.Nullable; + +import org.smartregister.reporting.R; + +import timber.log.Timber; + +/** + * Created by ndegwamartin on 2019-09-16. + */ +public class ProgressIndicator extends LinearLayout { + + private int progressBarBackgroundColor; + private int progressBarForegroundColor; + private int progressBarTitleColor; + private int progressDrawable; + private String title; + private String subTitle; + private int progress; + private boolean isTitleHidden; + private boolean isSubTitleHidden; + + private static final String PROGRESSBAR_FOREGROUND_COLOR = "progressbar_foreground_color"; + private static final String PROGRESSBAR_BACKGROUND_COLOR = "progressbar_background_color"; + private static final String PROGRESSBAR_TITLE = "progressbar_title"; + private static final String PROGRESSBAR_TITLE_COLOR = "progressbar_title_color"; + private static final String PROGRESSBAR_SUB_TITLE = "progressbar_sub_title"; + private static final String PROGRESSBAR_PROGRESS = "progressbar_progress"; + private static final String PROGRESSBAR_INSTANCE_STATE = "progressbar_instance_state"; + private static final String PROGRESSBAR_DRAWABLE = "progressbar_drawable"; + private AttributeSet attrs; + + public ProgressIndicator(Context context) { + super(context); + initView(); + + } + + public ProgressIndicator(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + initView(); + setupAttributes(attrs); + } + + public ProgressIndicator(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + initView(); + setupAttributes(attrs); + } + + @TargetApi(android.os.Build.VERSION_CODES.LOLLIPOP) + public ProgressIndicator(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + initView(); + setupAttributes(attrs); + } + + /** + * Set init configs for parent layout view + */ + private void initView() { + inflate(getContext(), R.layout.progress_indicator_view, this); + setGravity(Gravity.LEFT); + setOrientation(VERTICAL); + } + + /** + * @param attrs an attribute set styled attributes from theme + */ + protected void setupAttributes(AttributeSet attrs) { + this.attrs = attrs; + + TypedArray typedArray = getStyledAttributes(); + try { + + resetLayoutParams(typedArray); + + } finally { + + typedArray.recycle();// We must recycle TypedArray objects as they are shared + } + } + + protected TypedArray getStyledAttributes() { + return getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.ProgressIndicatorView, 0, 0); + } + + private void resetLayoutParams(TypedArray typedArray) { + + title = TextUtils.isEmpty(title) ? typedArray.getString(R.styleable.ProgressIndicatorView_title) : title; + title = TextUtils.isEmpty(title) ? progress + "%" : title; + + subTitle = TextUtils.isEmpty(subTitle) ? typedArray.getString(R.styleable.ProgressIndicatorView_subTitle) : subTitle; + + TextView titleTextView = findViewById(R.id.title_textview); + titleTextView.setText(title); + titleTextView.setVisibility(isTitleHidden ? View.GONE : View.VISIBLE); + + TextView subTitleTextView = findViewById(R.id.sub_title_textview); + subTitleTextView.setText(subTitle); + subTitleTextView.setVisibility(isSubTitleHidden ? View.GONE : View.VISIBLE); + + progress = progress > 0 ? progress : typedArray.getInteger(R.styleable.ProgressIndicatorView_progress, 0); + + + setResourceValues(typedArray); + + processProgressBarLayoutReset(progress, progressBarTitleColor, progressBarForegroundColor, progressBarBackgroundColor, progressDrawable); + + } + + private void setResourceValues(TypedArray typedArray) { + + progressBarTitleColor = progressBarTitleColor != 0 ? progressBarTitleColor : typedArray.getColor(R.styleable.ProgressIndicatorView_progressBarTitleColor, 0); + progressBarForegroundColor = progressBarForegroundColor != 0 ? progressBarForegroundColor : typedArray.getColor(R.styleable.ProgressIndicatorView_progressBarForegroundColor, 0); + progressBarBackgroundColor = progressBarBackgroundColor != 0 ? progressBarBackgroundColor : typedArray.getColor(R.styleable.ProgressIndicatorView_progressBarBackgroundColor, 0); + progressDrawable = progressDrawable != 0 ? progressDrawable : typedArray.getResourceId(R.styleable.ProgressIndicatorView_progressDrawable, 0); + + } + + private void processProgressBarLayoutReset(int progress, int progressBarTitleColor, int progressBarForegroundColor, int progressBarBackgroundColor, int progressDrawable) { + + ProgressBar progressBarView = findViewById(R.id.progressbar_view); + progressBarView.setProgressDrawable(progressDrawable > 0 ? getContext().getResources().getDrawable(progressDrawable) : progressBarView.getProgressDrawable()); + progressBarView.setProgress(progress); + + programmaticallyResetProgressBarBackgroundDrawable(progressBarView, progressBarForegroundColor, progressBarBackgroundColor); + + resetProgressBarTitleColor(progressBarTitleColor); + + } + + protected void resetProgressBarTitleColor(int progressBarTitleColor) { + if (progressBarTitleColor != 0) { + TextView titleTextView = findViewById(R.id.title_textview); + titleTextView.setTextColor(progressBarTitleColor); + } + } + + @TargetApi(Build.VERSION_CODES.M) + protected void programmaticallyResetProgressBarBackgroundDrawable(ProgressBar progressBarView, int progressBarForegroundColor, int progressBarBackgroundColor) { + try { + LayerDrawable progressBarDrawable = (LayerDrawable) progressBarView.getProgressDrawable().mutate(); + Drawable backgroundDrawable = progressBarDrawable.getDrawable(0).mutate(); + ClipDrawable clipDrawable = (ClipDrawable) progressBarDrawable.getDrawable(1).mutate(); + + if (progressBarBackgroundColor != 0) + backgroundDrawable.setColorFilter(progressBarBackgroundColor, PorterDuff.Mode.SRC_IN); + + if (progressBarForegroundColor != 0) { + + GradientDrawable gdDefault = new GradientDrawable(); + gdDefault.setColor(progressBarForegroundColor); + gdDefault.setCornerRadius(10); + gdDefault.setStroke(2, progressBarBackgroundColor); + + clipDrawable.setDrawable(gdDefault); + + } + } catch (Exception | NoSuchMethodError e) { + Timber.d(e); + } + } + + @Override + public Parcelable onSaveInstanceState() { + Bundle bundle = new Bundle(); + bundle.putParcelable(PROGRESSBAR_INSTANCE_STATE, super.onSaveInstanceState());// Store base view state + + bundle.putInt(PROGRESSBAR_FOREGROUND_COLOR, this.progressBarForegroundColor); + bundle.putInt(PROGRESSBAR_BACKGROUND_COLOR, this.progressBarBackgroundColor); + bundle.putString(PROGRESSBAR_TITLE, this.title); + bundle.putString(PROGRESSBAR_SUB_TITLE, this.subTitle); + bundle.putInt(PROGRESSBAR_PROGRESS, this.progress); + bundle.putInt(PROGRESSBAR_DRAWABLE, this.progressDrawable); + + + return bundle; + } + + @Override + public void onRestoreInstanceState(Parcelable state) { + Parcelable updatedState = null; + + if (state instanceof Bundle) { + Bundle bundle = (Bundle) state; + // Load back our custom view state + + this.progressBarTitleColor = bundle.getInt(PROGRESSBAR_TITLE_COLOR); + this.progressBarForegroundColor = bundle.getInt(PROGRESSBAR_FOREGROUND_COLOR); + this.progressBarBackgroundColor = bundle.getInt(PROGRESSBAR_BACKGROUND_COLOR); + this.title = bundle.getString(PROGRESSBAR_TITLE); + this.subTitle = bundle.getString(PROGRESSBAR_SUB_TITLE); + this.progress = bundle.getInt(PROGRESSBAR_PROGRESS); + this.progressDrawable = bundle.getInt(PROGRESSBAR_DRAWABLE); + + updatedState = bundle.getParcelable(PROGRESSBAR_INSTANCE_STATE);// Load base view state back + } + + super.onRestoreInstanceState(updatedState != null ? updatedState : state);// Pass base view state to super + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + + } + + private void refreshLayout() { + + TypedArray typedArray = getStyledAttributes(); + + try { + resetLayoutParams(typedArray); + invalidate(); + requestLayout(); + } finally { + typedArray.recycle(); + } + } + + public int getProgressBarTitleColor() { + return progressBarTitleColor; + } + + public void setProgressBarTitleColor(int progressBarTitleColor) { + this.progressBarTitleColor = progressBarTitleColor; + refreshLayout(); + } + + public int getProgressBarBackgroundColor() { + return progressBarBackgroundColor; + } + + /** + * Only works for API 23 and onwards other use a custom drawable xml to customize style + */ + @TargetApi(Build.VERSION_CODES.M) + public void setProgressBarBackgroundColor(int progressBarBackgroundColor) { + this.progressBarBackgroundColor = progressBarBackgroundColor; + refreshLayout(); + } + + public int getProgressBarForegroundColor() { + return progressBarForegroundColor; + } + + /** + * Only works for API 23 and onwards other use a custom drawable xml to customize style + */ + @TargetApi(Build.VERSION_CODES.M) + public void setProgressBarForegroundColor(int progressBarForegroundColor) { + this.progressBarForegroundColor = progressBarForegroundColor; + refreshLayout(); + } + + public String getTitle() { + return title; + } + + /** + * Sets title of indicator (top text) + */ + public void setTitle(String title) { + this.title = title; + refreshLayout(); + } + + public String getSubTitle() { + return subTitle; + } + + /** + * Sets subtitle of indicator (top text) + */ + public void setSubTitle(String subTitle) { + this.subTitle = subTitle; + refreshLayout(); + } + + public int getProgress() { + return progress; + } + + /** + * Sets progress of indicator bar + */ + public void setProgress(int progress) { + this.progress = progress; + refreshLayout(); + } + + /** + * Sets hides title of indicator + */ + public void hideTitle(boolean isHidden) { + this.isTitleHidden = isHidden; + refreshLayout(); + } + + public void hideSubTitle(boolean isHidden) { + this.isSubTitleHidden = isHidden; + refreshLayout(); + } + + public void setProgressDrawable(int progressDrawable) { + this.progressDrawable = progressDrawable; + refreshLayout(); + } + + public int getProgressDrawable() { + return progressDrawable; + } +} diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/ProgressIndicatorView.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/ProgressIndicatorView.java index 9baf76e2..91d33c9a 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/ProgressIndicatorView.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/ProgressIndicatorView.java @@ -1,313 +1,31 @@ package org.smartregister.reporting.view; -import android.annotation.TargetApi; import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Canvas; -import android.graphics.PorterDuff; -import android.graphics.drawable.ClipDrawable; -import android.graphics.drawable.Drawable; -import android.graphics.drawable.GradientDrawable; -import android.graphics.drawable.LayerDrawable; -import android.os.Build; -import android.os.Bundle; -import android.os.Parcelable; -import android.text.TextUtils; -import android.util.AttributeSet; -import android.view.Gravity; import android.view.View; -import android.widget.LinearLayout; -import android.widget.ProgressBar; -import android.widget.TextView; -import androidx.annotation.Nullable; +import org.jetbrains.annotations.Nullable; +import org.smartregister.reporting.contract.ReportContract; +import org.smartregister.reporting.factory.ProgressIndicatorFactory; +import org.smartregister.reporting.domain.ProgressIndicatorDisplayOptions; +import org.smartregister.reporting.util.ReportingUtil; -import org.smartregister.reporting.R; +public class ProgressIndicatorView implements ReportContract.IndicatorView { -import timber.log.Timber; + private Context context; + private ProgressIndicatorDisplayOptions displayOptions; + private ProgressIndicatorFactory progressIndicatorFactory; -/** - * Created by ndegwamartin on 2019-09-16. - */ -public class ProgressIndicatorView extends LinearLayout { - private int progressBarBackgroundColor; - private int progressBarForegroundColor; - private int progressDrawable; - private String title; - private String subTitle; - private int progress; - private boolean isTitleHidden; - private boolean isSubTitleHidden; - - private static final String PROGRESSBAR_FOREGROUND_COLOR = "progressbar_foreground_color"; - private static final String PROGRESSBAR_BACKGROUND_COLOR = "progressbar_background_color"; - private static final String PROGRESSBAR_TITLE = "progressbar_title"; - private static final String PROGRESSBAR_SUB_TITLE = "progressbar_sub_title"; - private static final String PROGRESSBAR_PROGRESS = "progressbar_progress"; - private static final String PROGRESSBAR_INSTANCE_STATE = "progressbar_instance_state"; - private static final String PROGRESSBAR_DRAWABLE = "progressbar_drawable"; - private AttributeSet attrs; - - public ProgressIndicatorView(Context context) { - super(context); - initView(); - - } - - public ProgressIndicatorView(Context context, @Nullable AttributeSet attrs) { - super(context, attrs); - initView(); - setupAttributes(attrs); - } - - public ProgressIndicatorView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - initView(); - setupAttributes(attrs); - } - - @TargetApi(android.os.Build.VERSION_CODES.LOLLIPOP) - public ProgressIndicatorView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - initView(); - setupAttributes(attrs); - } - - /** - * Set init configs for parent layout view - */ - private void initView() { - inflate(getContext(), R.layout.progress_indicator_view, this); - setGravity(Gravity.LEFT); - setOrientation(VERTICAL); - } - - /** - * @param attrs an attribute set styled attributes from theme - */ - protected void setupAttributes(AttributeSet attrs) { - this.attrs = attrs; - - TypedArray typedArray = getStyledAttributes(); - try { - - resetLayoutParams(typedArray); - - } finally { - - typedArray.recycle();// We must recycle TypedArray objects as they are shared - } - } - - protected TypedArray getStyledAttributes() { - return getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.ProgressIndicatorView, 0, 0); - } - - private void resetLayoutParams(TypedArray typedArray) { - - title = TextUtils.isEmpty(title) ? typedArray.getString(R.styleable.ProgressIndicatorView_title) : title; - title = TextUtils.isEmpty(title) ? progress + "%" : title; - - subTitle = TextUtils.isEmpty(subTitle) ? typedArray.getString(R.styleable.ProgressIndicatorView_subTitle) : subTitle; - - TextView titleTextView = findViewById(R.id.title_textview); - titleTextView.setText(title); - titleTextView.setVisibility(isTitleHidden ? View.GONE : View.VISIBLE); - - TextView subTitleTextView = findViewById(R.id.sub_title_textview); - subTitleTextView.setText(subTitle); - subTitleTextView.setVisibility(isSubTitleHidden ? View.GONE : View.VISIBLE); - - progress = progress > 0 ? progress : typedArray.getInteger(R.styleable.ProgressIndicatorView_progress, 0); - - - setResourceValues(typedArray); - - processProgressBarLayoutReset(progress, progressBarForegroundColor, progressBarBackgroundColor, progressDrawable); - - } - - private void setResourceValues(TypedArray typedArray) { - - progressBarForegroundColor = progressBarForegroundColor != 0 ? progressBarForegroundColor : typedArray.getColor(R.styleable.ProgressIndicatorView_progressBarForegroundColor, 0); - progressBarBackgroundColor = progressBarBackgroundColor != 0 ? progressBarBackgroundColor : typedArray.getColor(R.styleable.ProgressIndicatorView_progressBarBackgroundColor, 0); - progressDrawable = progressDrawable != 0 ? progressDrawable : typedArray.getResourceId(R.styleable.ProgressIndicatorView_progressDrawable, 0); - - } - - private void processProgressBarLayoutReset(int progress, int progressBarForegroundColor, int progressBarBackgroundColor, int progressDrawable) { - - ProgressBar progressBarView = findViewById(R.id.progressbar_view); - progressBarView.setProgressDrawable(progressDrawable > 0 ? getContext().getResources().getDrawable(progressDrawable) : progressBarView.getProgressDrawable()); - progressBarView.setProgress(progress); - - programmaticallyResetProgressBarBackgroundDrawable(progressBarView, progressBarForegroundColor, progressBarBackgroundColor); - - } - - @TargetApi(Build.VERSION_CODES.M) - protected void programmaticallyResetProgressBarBackgroundDrawable(ProgressBar progressBarView, int progressBarForegroundColor, int progressBarBackgroundColor) { - try { - LayerDrawable progressBarDrawable = (LayerDrawable) progressBarView.getProgressDrawable().mutate(); - Drawable backgroundDrawable = progressBarDrawable.getDrawable(0).mutate(); - ClipDrawable clipDrawable = (ClipDrawable) progressBarDrawable.getDrawable(1).mutate(); - - if (progressBarBackgroundColor != 0) - backgroundDrawable.setColorFilter(progressBarBackgroundColor, PorterDuff.Mode.SRC_IN); - - if (progressBarForegroundColor != 0) { - - GradientDrawable gdDefault = new GradientDrawable(); - gdDefault.setColor(progressBarForegroundColor); - gdDefault.setCornerRadius(10); - gdDefault.setStroke(2, progressBarBackgroundColor); - - clipDrawable.setDrawable(gdDefault); - - } - } catch (Exception | NoSuchMethodError e) { - Timber.d(e); - } + public ProgressIndicatorView(Context context, ProgressIndicatorDisplayOptions displayOptions) { + this.progressIndicatorFactory = new ProgressIndicatorFactory(); + this.context = context; + this.displayOptions = displayOptions; } + @Nullable @Override - public Parcelable onSaveInstanceState() { - Bundle bundle = new Bundle(); - bundle.putParcelable(PROGRESSBAR_INSTANCE_STATE, super.onSaveInstanceState());// Store base view state - - bundle.putInt(PROGRESSBAR_FOREGROUND_COLOR, this.progressBarForegroundColor); - bundle.putInt(PROGRESSBAR_BACKGROUND_COLOR, this.progressBarBackgroundColor); - bundle.putString(PROGRESSBAR_TITLE, this.title); - bundle.putString(PROGRESSBAR_SUB_TITLE, this.subTitle); - bundle.putInt(PROGRESSBAR_PROGRESS, this.progress); - bundle.putInt(PROGRESSBAR_DRAWABLE, this.progressDrawable); - - - return bundle; - } - - @Override - public void onRestoreInstanceState(Parcelable state) { - Parcelable updatedState = null; - - if (state instanceof Bundle) { - Bundle bundle = (Bundle) state; - // Load back our custom view state - - this.progressBarForegroundColor = bundle.getInt(PROGRESSBAR_FOREGROUND_COLOR); - this.progressBarBackgroundColor = bundle.getInt(PROGRESSBAR_BACKGROUND_COLOR); - this.title = bundle.getString(PROGRESSBAR_TITLE); - this.subTitle = bundle.getString(PROGRESSBAR_SUB_TITLE); - this.progress = bundle.getInt(PROGRESSBAR_PROGRESS); - this.progressDrawable = bundle.getInt(PROGRESSBAR_DRAWABLE); - - updatedState = bundle.getParcelable(PROGRESSBAR_INSTANCE_STATE);// Load base view state back - } - - super.onRestoreInstanceState(updatedState != null ? updatedState : state);// Pass base view state to super + public View createView() { + return ReportingUtil.getIndicatorView(displayOptions, progressIndicatorFactory, context); } - @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - - } - - private void refreshLayout() { - - TypedArray typedArray = getStyledAttributes(); - - try { - resetLayoutParams(typedArray); - invalidate(); - requestLayout(); - } finally { - typedArray.recycle(); - } - } - - public int getProgressBarBackgroundColor() { - return progressBarBackgroundColor; - } - - /** - * Only works for API 23 and onwards other use a custom drawable xml to customize style - */ - @TargetApi(Build.VERSION_CODES.M) - public void setProgressBarBackgroundColor(int progressBarBackgroundColor) { - this.progressBarBackgroundColor = progressBarBackgroundColor; - refreshLayout(); - } - - public int getProgressBarForegroundColor() { - return progressBarForegroundColor; - } - - /** - * Only works for API 23 and onwards other use a custom drawable xml to customize style - */ - @TargetApi(Build.VERSION_CODES.M) - public void setProgressBarForegroundColor(int progressBarForegroundColor) { - this.progressBarForegroundColor = progressBarForegroundColor; - refreshLayout(); - } - - public String getTitle() { - return title; - } - - /** - * Sets title of indicator (top text) - */ - public void setTitle(String title) { - this.title = title; - refreshLayout(); - } - - public String getSubTitle() { - return subTitle; - } - - /** - * Sets subtitle of indicator (top text) - */ - public void setSubTitle(String subTitle) { - this.subTitle = subTitle; - refreshLayout(); - } - - public int getProgress() { - return progress; - } - - /** - * Sets progress of indicator bar - */ - public void setProgress(int progress) { - this.progress = progress; - refreshLayout(); - } - - /** - * Sets hides title of indicator - */ - public void hideTitle(boolean isHidden) { - this.isTitleHidden = isHidden; - refreshLayout(); - } - - public void hideSubTitle(boolean isHidden) { - this.isSubTitleHidden = isHidden; - refreshLayout(); - } - - public void setProgressDrawable(int progressDrawable) { - this.progressDrawable = progressDrawable; - refreshLayout(); - } - - public int getProgressDrawable() { - return progressDrawable; - } } diff --git a/opensrp-reporting/src/main/res/layout/pie_chart_view.xml b/opensrp-reporting/src/main/res/layout/pie_chart_view.xml index e314abdd..76340e0e 100644 --- a/opensrp-reporting/src/main/res/layout/pie_chart_view.xml +++ b/opensrp-reporting/src/main/res/layout/pie_chart_view.xml @@ -36,8 +36,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/pie_indicator_label" - android:layout_marginTop="10dp" android:layout_alignParentStart="true" + android:layout_marginTop="10dp" android:text="Sample Note" /> @@ -45,8 +45,7 @@ + android:layout_height="250dp" /> + + + + + + + + + \ No newline at end of file diff --git a/opensrp-reporting/src/main/res/values/attrs_progress_indicator_view.xml b/opensrp-reporting/src/main/res/values/attrs_progress_indicator_view.xml index 538a0718..bff880af 100644 --- a/opensrp-reporting/src/main/res/values/attrs_progress_indicator_view.xml +++ b/opensrp-reporting/src/main/res/values/attrs_progress_indicator_view.xml @@ -3,6 +3,7 @@ + diff --git a/opensrp-reporting/src/main/res/values/colors.xml b/opensrp-reporting/src/main/res/values/colors.xml index b1e608b3..15e8b256 100644 --- a/opensrp-reporting/src/main/res/values/colors.xml +++ b/opensrp-reporting/src/main/res/values/colors.xml @@ -8,4 +8,6 @@ #DEDEDE #00b253 #b2f395 + #ecf1f7 + diff --git a/opensrp-reporting/src/main/res/values/testStyles.xml b/opensrp-reporting/src/main/res/values/testStyles.xml index 8740525e..b3d253c8 100644 --- a/opensrp-reporting/src/main/res/values/testStyles.xml +++ b/opensrp-reporting/src/main/res/values/testStyles.xml @@ -5,6 +5,7 @@ Sub Title 25 @drawable/progress_indicator_bg + @color/colorReportingIndicatorLabel @color/colorPastelGreen @color/colorSecondaryGreen diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/domain/PieChartIndicatorVisualizationTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/domain/PieChartIndicatorVisualizationTest.java index 1dff4fa6..97f96c19 100644 --- a/opensrp-reporting/src/test/java/org/smartregister/reporting/domain/PieChartIndicatorVisualizationTest.java +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/domain/PieChartIndicatorVisualizationTest.java @@ -46,7 +46,7 @@ public void pieChartIndicatorVisualizationBuilderInitsVisualization() { chartSlices.add(noSlice); // Build the chart - PieChartIndicatorVisualization pieChartIndicatorVisualization = new PieChartIndicatorVisualization.PieChartIndicatorVisualizationBuilder() + PieChartIndicatorDisplayOptions pieChartIndicatorVisualization = new PieChartIndicatorDisplayOptions.PieChartIndicatorVisualizationBuilder() .indicatorLabel(indicatorLabel) .chartHasLabels(true) .indicatorNote("Note") @@ -56,11 +56,11 @@ public void pieChartIndicatorVisualizationBuilderInitsVisualization() { .chartListener(null).build(); Assert.assertEquals(indicatorLabel, pieChartIndicatorVisualization.getIndicatorLabel()); - Assert.assertTrue(pieChartIndicatorVisualization.getChartData().hasLabels()); - Assert.assertTrue(pieChartIndicatorVisualization.getChartData().hasLabelsOutside()); - Assert.assertFalse(pieChartIndicatorVisualization.getChartData().hasCenterCircle()); - Assert.assertEquals(indicatorValue1, pieChartIndicatorVisualization.getChartData().getSlices().get(0).getValue(), 0.0001); - Assert.assertEquals(indicatorValue2, pieChartIndicatorVisualization.getChartData().getSlices().get(1).getValue(), 0.0001); + Assert.assertTrue(pieChartIndicatorVisualization.getPieChartConfig().hasLabels()); + Assert.assertTrue(pieChartIndicatorVisualization.getPieChartConfig().hasLabelsOutside()); + Assert.assertFalse(pieChartIndicatorVisualization.getPieChartConfig().hasCenterCircle()); + Assert.assertEquals(indicatorValue1, pieChartIndicatorVisualization.getPieChartConfig().getSlices().get(0).getValue(), 0.0001); + Assert.assertEquals(indicatorValue2, pieChartIndicatorVisualization.getPieChartConfig().getSlices().get(1).getValue(), 0.0001); } } diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java index dfa3e857..eab4394b 100644 --- a/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java @@ -7,9 +7,12 @@ import org.mockito.junit.MockitoJUnitRunner; import org.smartregister.reporting.contract.ReportContract; import org.smartregister.reporting.domain.IndicatorTally; -import org.smartregister.reporting.model.NumericDisplayModel; +import org.smartregister.reporting.domain.NumericIndicatorDisplayOptions; +import org.smartregister.reporting.domain.PieChartIndicatorDisplayOptions; +import org.smartregister.reporting.domain.PieChartSlice; import org.smartregister.reporting.util.ReportingUtil; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -17,9 +20,11 @@ import java.util.Map; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.smartregister.reporting.BaseUnitTest.getDateTime; -import static org.smartregister.reporting.util.ReportingUtil.getIndicatorDisplayModel; +import static org.smartregister.reporting.util.ReportingUtil.getPieChartSlice; @RunWith(MockitoJUnitRunner.class) public class ReportingUtilTest { @@ -70,17 +75,43 @@ public void testGetIndicatorDisplayModelTotalAndLatestCount() { List indicatorTallies = Collections.unmodifiableList(Collections.unmodifiableList(Arrays.asList(tally1, tally2, tally3, tally4))); //Test get model with total count - NumericDisplayModel NumericDisplayModel = getIndicatorDisplayModel(ReportContract.IndicatorView.CountType.TOTAL_COUNT, "indicator1", 182998, indicatorTallies); - assertNotNull(NumericDisplayModel); - assertEquals(12, NumericDisplayModel.getCount(), 0); - assertEquals("indicator1", NumericDisplayModel.getIndicatorCode()); - assertEquals(182998, NumericDisplayModel.getLabelStringResource()); + NumericIndicatorDisplayOptions displayOptions1 = ReportingUtil.getNumericIndicatorDisplayOptions(ReportContract.IndicatorView.CountType.TOTAL_COUNT, + "indicator1", + "first indicator", indicatorTallies); + assertNotNull(displayOptions1); + assertEquals(12, displayOptions1.getValue(), 0); + assertEquals("first indicator", displayOptions1.getIndicatorLabel()); - //Test get model with total count - NumericDisplayModel NumericDisplayModel2 = getIndicatorDisplayModel(ReportContract.IndicatorView.CountType.LATEST_COUNT, "indicator2", 182999, indicatorTallies); - assertNotNull(NumericDisplayModel2); - assertEquals(13, NumericDisplayModel2.getCount(), 0); - assertEquals("indicator2", NumericDisplayModel2.getIndicatorCode()); - assertEquals(182999, NumericDisplayModel2.getLabelStringResource()); + //Test get model with latest count + NumericIndicatorDisplayOptions displayOptions2 = ReportingUtil.getNumericIndicatorDisplayOptions(ReportContract.IndicatorView.CountType.LATEST_COUNT, + "indicator2", + "second indicator", indicatorTallies); + assertNotNull(displayOptions2); + assertEquals(13, displayOptions2.getValue(), 0); + assertEquals("second indicator", displayOptions2.getIndicatorLabel()); + } + + @Test + public void getPieChartDisplayOptionsReturnsCorrectOptions() { + PieChartSlice indicator2_1 = getPieChartSlice(ReportContract.IndicatorView.CountType.LATEST_COUNT, "IND-1", "slice 1", 0, null); + PieChartSlice indicator2_2 = getPieChartSlice(ReportContract.IndicatorView.CountType.LATEST_COUNT, "IND-2", "slice 2", 0, null); + List slices = new ArrayList<>(); + slices.add(indicator2_1); + slices.add(indicator2_2); + PieChartIndicatorDisplayOptions options = ReportingUtil.getPieChartDisplayOptions(slices, "Test Chart", "", null); + + assertEquals("Test Chart", options.getIndicatorLabel()); + assertNotNull(options.getPieChartConfig().getSlices()); + assertEquals("slice 2", options.getPieChartConfig().getSlices().get(1).getLabel()); + assertTrue(options.getPieChartConfig().hasLabels()); + assertFalse(options.getPieChartConfig().hasCenterCircle()); + } + + @Test + public void canFormatDecimals() { + assertEquals("12.301", ReportingUtil.formatDecimal(12.30123)); + assertEquals("12.301", ReportingUtil.formatDecimal(12.301)); + assertEquals("12.3", ReportingUtil.formatDecimal(12.3001)); + assertEquals("12", ReportingUtil.formatDecimal(12.0)); } } diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/model/BaseReportIndicatorsModelTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/model/BaseReportIndicatorsModelTest.java index 0643fffb..ad75d185 100644 --- a/opensrp-reporting/src/test/java/org/smartregister/reporting/model/BaseReportIndicatorsModelTest.java +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/model/BaseReportIndicatorsModelTest.java @@ -13,7 +13,6 @@ import org.powermock.modules.junit4.PowerMockRunner; import org.smartregister.reporting.ReportingLibrary; import org.smartregister.reporting.dao.ReportIndicatorDaoImpl; -import org.smartregister.reporting.domain.BaseReportIndicatorsModel; import org.smartregister.reporting.domain.IndicatorQuery; import org.smartregister.reporting.domain.ReportIndicator; import org.smartregister.reporting.repository.DailyIndicatorCountRepository; diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/shadow/ReportUtilShadowHelper.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/shadow/ReportUtilShadowHelper.java new file mode 100644 index 00000000..b25e1f7c --- /dev/null +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/shadow/ReportUtilShadowHelper.java @@ -0,0 +1,23 @@ +package org.smartregister.reporting.shadow; + +import android.content.Context; +import android.view.View; + +import org.robolectric.annotation.Implementation; +import org.robolectric.annotation.Implements; +import org.smartregister.reporting.domain.ReportingIndicatorDisplayOptions; +import org.smartregister.reporting.factory.IndicatorVisualisationFactory; +import org.smartregister.reporting.util.ReportingUtil; + +@Implements(ReportingUtil.class) +public class ReportUtilShadowHelper { + + + + @Implementation + public static View getIndicatorView(ReportingIndicatorDisplayOptions displayOptions, + IndicatorVisualisationFactory visualisationFactory, Context context) { + return visualisationFactory.getIndicatorView(displayOptions, context); + } + +} diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/view/NumericDisplayFactoryTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/view/NumericDisplayFactoryTest.java index 387d3391..29bdce91 100644 --- a/opensrp-reporting/src/test/java/org/smartregister/reporting/view/NumericDisplayFactoryTest.java +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/view/NumericDisplayFactoryTest.java @@ -20,7 +20,7 @@ import org.powermock.modules.junit4.rule.PowerMockRule; import org.smartregister.reporting.BaseUnitTest; import org.smartregister.reporting.R; -import org.smartregister.reporting.domain.NumericIndicatorVisualization; +import org.smartregister.reporting.domain.NumericIndicatorDisplayOptions; import org.smartregister.reporting.factory.NumericDisplayFactory; @PrepareForTest(LayoutInflater.class) @@ -30,7 +30,7 @@ public class NumericDisplayFactoryTest extends BaseUnitTest { public PowerMockRule rule = new PowerMockRule(); @Mock - private NumericIndicatorVisualization visualization; + private NumericIndicatorDisplayOptions visualization; @Mock private Context context; diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/view/PieChartFactoryTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/view/PieChartFactoryTest.java index 0ad4eeb1..4d18952e 100644 --- a/opensrp-reporting/src/test/java/org/smartregister/reporting/view/PieChartFactoryTest.java +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/view/PieChartFactoryTest.java @@ -19,8 +19,8 @@ import org.powermock.modules.junit4.rule.PowerMockRule; import org.smartregister.reporting.BaseUnitTest; import org.smartregister.reporting.R; -import org.smartregister.reporting.domain.PieChartIndicatorData; -import org.smartregister.reporting.domain.PieChartIndicatorVisualization; +import org.smartregister.reporting.domain.PieChartConfig; +import org.smartregister.reporting.domain.PieChartIndicatorDisplayOptions; import org.smartregister.reporting.factory.PieChartFactory; import lecho.lib.hellocharts.view.PieChartView; @@ -32,7 +32,7 @@ public class PieChartFactoryTest extends BaseUnitTest { public PowerMockRule rule = new PowerMockRule(); @Mock - private PieChartIndicatorVisualization visualization; + private PieChartIndicatorDisplayOptions visualization; @Mock private Context context; @@ -56,7 +56,7 @@ public class PieChartFactoryTest extends BaseUnitTest { private LinearLayout rootLayout; @Mock - private PieChartIndicatorData chartConfiguration; + private PieChartConfig chartConfiguration; @InjectMocks private PieChartFactory pieChartFactory; @@ -76,7 +76,7 @@ public void getPieChartIndicatorViewReturnsCorrectView() { Mockito.doReturn(chartNoteTextView).when(rootLayout).findViewById(R.id.pie_note_label); Mockito.doReturn(numericValueTextView).when(rootLayout).findViewById(R.id.numeric_indicator_value); Mockito.doReturn(pieChartView).when(rootLayout).findViewById(R.id.pie_chart); - Mockito.doReturn(chartConfiguration).when(visualization).getChartData(); + Mockito.doReturn(chartConfiguration).when(visualization).getPieChartConfig(); View view = pieChartFactorySpy.getIndicatorView(visualization, context); Assert.assertNotNull(view); Assert.assertTrue(view instanceof LinearLayout); diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorFactoryTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorFactoryTest.java new file mode 100644 index 00000000..78ca998b --- /dev/null +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorFactoryTest.java @@ -0,0 +1,77 @@ +package org.smartregister.reporting.view; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.TextView; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.rule.PowerMockRule; +import org.smartregister.reporting.BaseUnitTest; +import org.smartregister.reporting.R; +import org.smartregister.reporting.domain.ProgressIndicatorConfig; +import org.smartregister.reporting.domain.ProgressIndicatorDisplayOptions; +import org.smartregister.reporting.factory.ProgressIndicatorFactory; + +@PrepareForTest(LayoutInflater.class) +public class ProgressIndicatorFactoryTest extends BaseUnitTest { + + @Rule + public PowerMockRule rule = new PowerMockRule(); + + @Mock + ProgressIndicatorDisplayOptions displayOptions; + + @Mock + private Context context; + + @Mock + private TextView indicatorLabel; + + @Mock + private LinearLayout rootLayout; + + @Mock + private LayoutInflater layoutInflater; + + @Mock + private ProgressIndicator progressWidget; + + @Mock + private ProgressIndicatorConfig config; + + @InjectMocks + private ProgressIndicatorFactory progressIndicatorFactory; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + + @Test + public void getProgressIndicatorViewReturnsCorrectView() { + ProgressIndicatorFactory factorySpy = Mockito.spy(progressIndicatorFactory); + PowerMockito.mockStatic(LayoutInflater.class); + PowerMockito.when(LayoutInflater.from(context)).thenReturn(layoutInflater); + Mockito.doReturn(rootLayout).when(layoutInflater).inflate(R.layout.progress_indicator_factory_layout, null); + Mockito.doReturn(indicatorLabel).when(rootLayout).findViewById(R.id.tv_indicator_label); + Mockito.doReturn(config).when(displayOptions).getConfig(); + Mockito.doReturn(progressWidget).when(rootLayout).findViewById(R.id.progressIndicatorView); + + View view = factorySpy.getIndicatorView(displayOptions, context); + Assert.assertNotNull(view); + Assert.assertTrue(view instanceof LinearLayout); + } + +} diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorTest.java new file mode 100644 index 00000000..75349b8d --- /dev/null +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorTest.java @@ -0,0 +1,171 @@ +package org.smartregister.reporting.view; + +import android.content.res.Resources; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.os.Parcelable; +import android.util.AttributeSet; +import android.view.View; +import android.widget.TextView; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.robolectric.Robolectric; +import org.robolectric.RuntimeEnvironment; +import org.smartregister.reporting.BaseUnitTest; +import org.smartregister.reporting.R; + +/** + * Created by ndegwamartin on 2019-10-11. + */ +public class ProgressIndicatorTest extends BaseUnitTest { + + private AttributeSet attributeSet; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + attributeSet = Robolectric.buildAttributeSet() + .addAttribute(R.attr.subtitle, "subtitle") + .build(); + } + + @Test + public void testConstructorsInstantiateSuccesfully() { + + ProgressIndicator view = new ProgressIndicator(RuntimeEnvironment.application); + Assert.assertNotNull(view); + + + view = new ProgressIndicator(RuntimeEnvironment.application, attributeSet); + Assert.assertNotNull(view); + + + view = new ProgressIndicator(RuntimeEnvironment.application, attributeSet, R.styleable.ProgressIndicatorView_progress); + Assert.assertNotNull(view); + + + view = new ProgressIndicator(RuntimeEnvironment.application, attributeSet, R.styleable.ProgressIndicatorView_progress, R.style.progressIndicatorViewTestStyle); + Assert.assertNotNull(view); + } + + @Test + public void testSetupAttributesInitializesStyleAttributesWithCorrectValues() { + + Resources.Theme theme = RuntimeEnvironment.application.getResources().newTheme(); + theme.applyStyle(R.style.progressIndicatorViewTestStyle, true); + + int[] viewAttr = R.styleable.ProgressIndicatorView; + TypedArray styledAttributes = theme.obtainStyledAttributes(viewAttr); + + ProgressIndicator actualObject = new ProgressIndicator(RuntimeEnvironment.application); + ProgressIndicator view = Mockito.spy(actualObject); + Assert.assertNotNull(view); + + Mockito.when(view.getStyledAttributes()).thenReturn(styledAttributes); + + view.setupAttributes(attributeSet); + + Assert.assertEquals("Test Title", view.getTitle()); + Assert.assertEquals("Sub Title", view.getSubTitle()); + Assert.assertEquals(25, view.getProgress()); + Assert.assertEquals(R.drawable.progress_indicator_bg, view.getProgressDrawable()); + Assert.assertEquals(RuntimeEnvironment.application.getResources().getColor(R.color.colorSecondaryGreen), view.getProgressBarBackgroundColor()); + Assert.assertEquals(RuntimeEnvironment.application.getResources().getColor(R.color.colorPastelGreen), view.getProgressBarForegroundColor()); + + } + + @Test + public void testObjectSettersOverrideXMLStyledAttributes() { + + Resources.Theme theme = RuntimeEnvironment.application.getResources().newTheme(); + theme.applyStyle(R.style.progressIndicatorViewTestStyle, true); + + ProgressIndicator actualObject = new ProgressIndicator(RuntimeEnvironment.application); + ProgressIndicator view = Mockito.spy(actualObject); + view.setupAttributes(attributeSet); + + view.setTitle("New Test Title"); + view.setSubTitle("New Sub Title"); + view.setProgress(35); + view.setProgressDrawable(R.drawable.login_background); + view.setProgressBarForegroundColor(RuntimeEnvironment.application.getResources().getColor(R.color.colorAccent)); + view.setProgressBarBackgroundColor(RuntimeEnvironment.application.getResources().getColor(R.color.colorPrimaryDark)); + + Assert.assertEquals("New Test Title", view.getTitle()); + Assert.assertEquals("New Sub Title", view.getSubTitle()); + Assert.assertEquals(35, view.getProgress()); + Assert.assertEquals(R.drawable.login_background, view.getProgressDrawable()); + Assert.assertEquals(RuntimeEnvironment.application.getResources().getColor(R.color.colorPrimaryDark), view.getProgressBarBackgroundColor()); + Assert.assertEquals(RuntimeEnvironment.application.getResources().getColor(R.color.colorAccent), view.getProgressBarForegroundColor()); + + } + + + @Test + public void testSaveInstanceStateSavesAndRestoresStateCorrectly() { + + Resources.Theme theme = RuntimeEnvironment.application.getResources().newTheme(); + theme.applyStyle(R.style.progressIndicatorViewTestStyle, true); + + ProgressIndicator actualObject = new ProgressIndicator(RuntimeEnvironment.application, attributeSet); + ProgressIndicator view = Mockito.spy(actualObject); + + view.setTitle("Test Title"); + view.setSubTitle("Sub Title"); + view.setProgress(25); + view.setProgressDrawable(R.drawable.progress_indicator_bg); + view.setProgressBarForegroundColor(RuntimeEnvironment.application.getResources().getColor(R.color.colorSecondaryGreen)); + view.setProgressBarBackgroundColor(RuntimeEnvironment.application.getResources().getColor(R.color.colorPrimaryDark)); + + Parcelable saveInstanceState = view.onSaveInstanceState(); + + //clear values + view.setTitle(null); + view.setSubTitle(null); + view.setProgress(0); + view.setProgressDrawable(R.drawable.bottom_bar_initials_background);//set any random bg + view.setProgressBarForegroundColor(1); + view.setProgressBarBackgroundColor(1); + + view.onRestoreInstanceState(saveInstanceState); + + Assert.assertEquals("Test Title", view.getTitle()); + Assert.assertEquals("Sub Title", view.getSubTitle()); + Assert.assertEquals(25, view.getProgress()); + Assert.assertEquals(R.drawable.progress_indicator_bg, view.getProgressDrawable()); + Assert.assertEquals(RuntimeEnvironment.application.getResources().getColor(R.color.colorPrimaryDark), view.getProgressBarBackgroundColor()); + Assert.assertEquals(RuntimeEnvironment.application.getResources().getColor(R.color.colorSecondaryGreen), view.getProgressBarForegroundColor()); + + } + + @Test + public void testSettingTitleVisiblityConfigurationsUpdateViewTitlesCorrectly() { + + Resources.Theme theme = RuntimeEnvironment.application.getResources().newTheme(); + theme.applyStyle(R.style.progressIndicatorViewTestStyle, true); + + ProgressIndicator actualObject = new ProgressIndicator(RuntimeEnvironment.application); + ProgressIndicator view = Mockito.spy(actualObject); + view.onDraw(Mockito.mock(Canvas.class)); + Assert.assertNotNull(view); + + TextView titleTextView = view.findViewById(R.id.title_textview); + TextView subTitleTextView = view.findViewById(R.id.sub_title_textview); + + Assert.assertEquals(View.VISIBLE, titleTextView.getVisibility()); + Assert.assertEquals(View.VISIBLE, subTitleTextView.getVisibility()); + + view.hideTitle(true); + view.hideSubTitle(true); + + view.setupAttributes(attributeSet); + + Assert.assertEquals(View.GONE, titleTextView.getVisibility()); + Assert.assertEquals(View.GONE, subTitleTextView.getVisibility()); + + } +} diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorViewTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorViewTest.java index e5f2ff2b..aabe8517 100644 --- a/opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorViewTest.java +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorViewTest.java @@ -1,171 +1,35 @@ package org.smartregister.reporting.view; -import android.content.res.Resources; -import android.content.res.TypedArray; -import android.graphics.Canvas; -import android.os.Parcelable; -import android.util.AttributeSet; import android.view.View; -import android.widget.TextView; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.robolectric.Robolectric; import org.robolectric.RuntimeEnvironment; import org.smartregister.reporting.BaseUnitTest; -import org.smartregister.reporting.R; +import org.smartregister.reporting.domain.ProgressIndicatorDisplayOptions; -/** - * Created by ndegwamartin on 2019-10-11. - */ -public class ProgressIndicatorViewTest extends BaseUnitTest { - private AttributeSet attributeSet; +public class ProgressIndicatorViewTest extends BaseUnitTest { @Before public void setUp() { MockitoAnnotations.initMocks(this); - attributeSet = Robolectric.buildAttributeSet() - .addAttribute(R.attr.subtitle, "subtitle") - .build(); - } - - @Test - public void testConstructorsInstantiateSuccesfully() { - - ProgressIndicatorView view = new ProgressIndicatorView(RuntimeEnvironment.application); - Assert.assertNotNull(view); - - - view = new ProgressIndicatorView(RuntimeEnvironment.application, attributeSet); - Assert.assertNotNull(view); - - - view = new ProgressIndicatorView(RuntimeEnvironment.application, attributeSet, R.styleable.ProgressIndicatorView_progress); - Assert.assertNotNull(view); - - - view = new ProgressIndicatorView(RuntimeEnvironment.application, attributeSet, R.styleable.ProgressIndicatorView_progress, R.style.progressIndicatorViewTestStyle); - Assert.assertNotNull(view); - } - - @Test - public void testSetupAttributesInitializesStyleAttributesWithCorrectValues() { - - Resources.Theme theme = RuntimeEnvironment.application.getResources().newTheme(); - theme.applyStyle(R.style.progressIndicatorViewTestStyle, true); - - int[] viewAttr = R.styleable.ProgressIndicatorView; - TypedArray styledAttributes = theme.obtainStyledAttributes(viewAttr); - - ProgressIndicatorView actualObject = new ProgressIndicatorView(RuntimeEnvironment.application); - ProgressIndicatorView view = Mockito.spy(actualObject); - Assert.assertNotNull(view); - - Mockito.when(view.getStyledAttributes()).thenReturn(styledAttributes); - - view.setupAttributes(attributeSet); - - Assert.assertEquals("Test Title", view.getTitle()); - Assert.assertEquals("Sub Title", view.getSubTitle()); - Assert.assertEquals(25, view.getProgress()); - Assert.assertEquals(R.drawable.progress_indicator_bg, view.getProgressDrawable()); - Assert.assertEquals(RuntimeEnvironment.application.getResources().getColor(R.color.colorSecondaryGreen), view.getProgressBarBackgroundColor()); - Assert.assertEquals(RuntimeEnvironment.application.getResources().getColor(R.color.colorPastelGreen), view.getProgressBarForegroundColor()); - - } - - @Test - public void testObjectSettersOverrideXMLStyledAttributes() { - - Resources.Theme theme = RuntimeEnvironment.application.getResources().newTheme(); - theme.applyStyle(R.style.progressIndicatorViewTestStyle, true); - - ProgressIndicatorView actualObject = new ProgressIndicatorView(RuntimeEnvironment.application); - ProgressIndicatorView view = Mockito.spy(actualObject); - view.setupAttributes(attributeSet); - - view.setTitle("New Test Title"); - view.setSubTitle("New Sub Title"); - view.setProgress(35); - view.setProgressDrawable(R.drawable.login_background); - view.setProgressBarForegroundColor(RuntimeEnvironment.application.getResources().getColor(R.color.colorAccent)); - view.setProgressBarBackgroundColor(RuntimeEnvironment.application.getResources().getColor(R.color.colorPrimaryDark)); - - Assert.assertEquals("New Test Title", view.getTitle()); - Assert.assertEquals("New Sub Title", view.getSubTitle()); - Assert.assertEquals(35, view.getProgress()); - Assert.assertEquals(R.drawable.login_background, view.getProgressDrawable()); - Assert.assertEquals(RuntimeEnvironment.application.getResources().getColor(R.color.colorPrimaryDark), view.getProgressBarBackgroundColor()); - Assert.assertEquals(RuntimeEnvironment.application.getResources().getColor(R.color.colorAccent), view.getProgressBarForegroundColor()); - - } - - - @Test - public void testSaveInstanceStateSavesAndRestoresStateCorrectly() { - - Resources.Theme theme = RuntimeEnvironment.application.getResources().newTheme(); - theme.applyStyle(R.style.progressIndicatorViewTestStyle, true); - - ProgressIndicatorView actualObject = new ProgressIndicatorView(RuntimeEnvironment.application, attributeSet); - ProgressIndicatorView view = Mockito.spy(actualObject); - - view.setTitle("Test Title"); - view.setSubTitle("Sub Title"); - view.setProgress(25); - view.setProgressDrawable(R.drawable.progress_indicator_bg); - view.setProgressBarForegroundColor(RuntimeEnvironment.application.getResources().getColor(R.color.colorSecondaryGreen)); - view.setProgressBarBackgroundColor(RuntimeEnvironment.application.getResources().getColor(R.color.colorPrimaryDark)); - - Parcelable saveInstanceState = view.onSaveInstanceState(); - - //clear values - view.setTitle(null); - view.setSubTitle(null); - view.setProgress(0); - view.setProgressDrawable(R.drawable.bottom_bar_initials_background);//set any random bg - view.setProgressBarForegroundColor(1); - view.setProgressBarBackgroundColor(1); - - view.onRestoreInstanceState(saveInstanceState); - - Assert.assertEquals("Test Title", view.getTitle()); - Assert.assertEquals("Sub Title", view.getSubTitle()); - Assert.assertEquals(25, view.getProgress()); - Assert.assertEquals(R.drawable.progress_indicator_bg, view.getProgressDrawable()); - Assert.assertEquals(RuntimeEnvironment.application.getResources().getColor(R.color.colorPrimaryDark), view.getProgressBarBackgroundColor()); - Assert.assertEquals(RuntimeEnvironment.application.getResources().getColor(R.color.colorSecondaryGreen), view.getProgressBarForegroundColor()); - } @Test - public void testSettingTitleVisiblityConfigurationsUpdateViewTitlesCorrectly() { - - Resources.Theme theme = RuntimeEnvironment.application.getResources().newTheme(); - theme.applyStyle(R.style.progressIndicatorViewTestStyle, true); - - ProgressIndicatorView actualObject = new ProgressIndicatorView(RuntimeEnvironment.application); - ProgressIndicatorView view = Mockito.spy(actualObject); - view.onDraw(Mockito.mock(Canvas.class)); - Assert.assertNotNull(view); - - TextView titleTextView = view.findViewById(R.id.title_textview); - TextView subTitleTextView = view.findViewById(R.id.sub_title_textview); - - Assert.assertEquals(View.VISIBLE, titleTextView.getVisibility()); - Assert.assertEquals(View.VISIBLE, subTitleTextView.getVisibility()); - - view.hideTitle(true); - view.hideSubTitle(true); - - view.setupAttributes(attributeSet); - - Assert.assertEquals(View.GONE, titleTextView.getVisibility()); - Assert.assertEquals(View.GONE, subTitleTextView.getVisibility()); - + public void createViewGetsIndicatorView() { + ProgressIndicatorDisplayOptions displayOptions = new ProgressIndicatorDisplayOptions.ProgressIndicatorBuilder() + .withIndicatorLabel("Number of tasks") + .withProgressValue(80) + .withProgressIndicatorTitle("50%") + .withProgressIndicatorTitleColor(0) + .withForegroundColor(1) + .withBackgroundColor(2) + .build(); + ProgressIndicatorView progressIndicatorView = new ProgressIndicatorView(RuntimeEnvironment.application, displayOptions); + View returnedView = progressIndicatorView.createView(); + Assert.assertNotNull(returnedView); } } diff --git a/sample/src/main/java/org/smartregister/sample/presenter/SamplePresenter.java b/sample/src/main/java/org/smartregister/sample/presenter/SamplePresenter.java index d4e5884f..993728cc 100644 --- a/sample/src/main/java/org/smartregister/sample/presenter/SamplePresenter.java +++ b/sample/src/main/java/org/smartregister/sample/presenter/SamplePresenter.java @@ -1,7 +1,7 @@ package org.smartregister.sample.presenter; import org.smartregister.reporting.contract.ReportContract; -import org.smartregister.reporting.domain.BaseReportIndicatorsModel; +import org.smartregister.reporting.model.BaseReportIndicatorsModel; import org.smartregister.reporting.domain.IndicatorQuery; import org.smartregister.reporting.domain.IndicatorTally; import org.smartregister.reporting.domain.ReportIndicator; diff --git a/sample/src/main/java/org/smartregister/sample/view/DashboardFragment.java b/sample/src/main/java/org/smartregister/sample/view/DashboardFragment.java index 38d2f06d..6256035d 100644 --- a/sample/src/main/java/org/smartregister/sample/view/DashboardFragment.java +++ b/sample/src/main/java/org/smartregister/sample/view/DashboardFragment.java @@ -15,8 +15,8 @@ import org.smartregister.reporting.contract.ReportContract; import org.smartregister.reporting.domain.IndicatorTally; +import org.smartregister.reporting.domain.NumericIndicatorDisplayOptions; import org.smartregister.reporting.domain.PieChartSlice; -import org.smartregister.reporting.model.NumericDisplayModel; import org.smartregister.reporting.view.NumericIndicatorView; import org.smartregister.reporting.view.PieChartIndicatorView; import org.smartregister.sample.R; @@ -29,8 +29,8 @@ import static org.smartregister.reporting.contract.ReportContract.IndicatorView.CountType.LATEST_COUNT; import static org.smartregister.reporting.contract.ReportContract.IndicatorView.CountType.TOTAL_COUNT; import static org.smartregister.reporting.util.ReportingUtil.addPieChartSlices; -import static org.smartregister.reporting.util.ReportingUtil.getIndicatorDisplayModel; -import static org.smartregister.reporting.util.ReportingUtil.getPieChartDisplayModel; +import static org.smartregister.reporting.util.ReportingUtil.getNumericIndicatorDisplayOptions; +import static org.smartregister.reporting.util.ReportingUtil.getPieChartDisplayOptions; import static org.smartregister.reporting.util.ReportingUtil.getPieChartSlice; public class DashboardFragment extends Fragment implements ReportContract.View, LoaderManager.LoaderCallbacks>> { @@ -104,15 +104,15 @@ public void setIndicatorTallies(List> indicatorTalli } private void createSampleReportViews(ViewGroup mainLayout) { - NumericDisplayModel indicator1 = getIndicatorDisplayModel(TOTAL_COUNT, ChartUtil.numericIndicatorKey, R.string.total_under_5_count, indicatorTallies); - mainLayout.addView(new NumericIndicatorView(getContext(), indicator1).createView()); + NumericIndicatorDisplayOptions intDisplay = getNumericIndicatorDisplayOptions(TOTAL_COUNT, ChartUtil.numericIndicatorKey, getString(R.string.total_under_5_count), indicatorTallies); + mainLayout.addView(new NumericIndicatorView(getContext(), intDisplay).createView()); PieChartSlice indicator2_1 = getPieChartSlice(LATEST_COUNT, ChartUtil.pieChartYesIndicatorKey, getResources().getString(R.string.yes_slice_label), getResources().getColor(R.color.colorPieChartGreen), indicatorTallies); PieChartSlice indicator2_2 = getPieChartSlice(LATEST_COUNT, ChartUtil.pieChartNoIndicatorKey, getResources().getString(R.string.no_button_label), getResources().getColor(R.color.colorPieChartRed), indicatorTallies); - mainLayout.addView(new PieChartIndicatorView(getContext(), getPieChartDisplayModel(addPieChartSlices(indicator2_1, indicator2_2), R.string.num_of_lieterate_children_0_60_label, R.string.sample_note, null)).createView()); + mainLayout.addView(new PieChartIndicatorView(getContext(), getPieChartDisplayOptions(addPieChartSlices(indicator2_1, indicator2_2), getString(R.string.num_of_lieterate_children_0_60_label), getString(R.string.sample_note), null)).createView()); - NumericDisplayModel floatIndicatorCount = getIndicatorDisplayModel(TOTAL_COUNT, "S_IND_005", R.string.float_count, indicatorTallies); - mainLayout.addView(new NumericIndicatorView(getContext(), floatIndicatorCount).createView()); + NumericIndicatorDisplayOptions floatDisplay = getNumericIndicatorDisplayOptions(TOTAL_COUNT, "S_IND_005", getContext().getString(R.string.float_count), indicatorTallies); + mainLayout.addView(new NumericIndicatorView(getContext(), floatDisplay).createView()); } @NonNull diff --git a/sample/src/main/java/org/smartregister/sample/view/ResourcesFragment.java b/sample/src/main/java/org/smartregister/sample/view/ResourcesFragment.java index 1bcf44c7..83009712 100644 --- a/sample/src/main/java/org/smartregister/sample/view/ResourcesFragment.java +++ b/sample/src/main/java/org/smartregister/sample/view/ResourcesFragment.java @@ -11,7 +11,7 @@ import android.view.ViewGroup; import android.widget.Toast; -import org.smartregister.reporting.view.ProgressIndicatorView; +import org.smartregister.reporting.view.ProgressIndicator; import org.smartregister.reporting.view.TableView; import org.smartregister.sample.R; @@ -59,7 +59,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - ProgressIndicatorView progressWidget = getActivity().findViewById(R.id.progressIndicatorView); + ProgressIndicator progressWidget = getActivity().findViewById(R.id.progressIndicatorView); Integer valA = getRange(14, 99); progressWidget.setProgress(valA); progressWidget.setTitle(valA + "%"); diff --git a/sample/src/main/res/layout/fragment_resources.xml b/sample/src/main/res/layout/fragment_resources.xml index ed3e16d5..ed0f3974 100644 --- a/sample/src/main/res/layout/fragment_resources.xml +++ b/sample/src/main/res/layout/fragment_resources.xml @@ -17,14 +17,14 @@ android:layout_height="wrap_content" android:orientation="horizontal"> - -