diff --git a/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotFunctionSettingsActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotFunctionSettingsActivity.java index dfbdeee3..ad2dc0e3 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotFunctionSettingsActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotFunctionSettingsActivity.java @@ -97,7 +97,8 @@ public class CalculatorPlotFunctionSettingsActivity extends SherlockFragmentActi final PlotLineColor newPlotLineColor = PlotLineColor.values()[position]; int newLineColor = newPlotLineColor.getColor(); if ( newLineColor != plotFunction.getPlotLineDef().getLineColor() ) { - final PlotFunction newPlotFunction = new PlotFunction(plotFunction.getXyFunction(), PlotLineDef.changeLineColor(plotFunction.getPlotLineDef(), newLineColor)); + final PlotLineDef newPlotLineDef = PlotLineDef.changeLineColor(plotFunction.getPlotLineDef(), newLineColor); + final PlotFunction newPlotFunction = PlotFunction.changePlotLineDef(plotFunction, newPlotLineDef); if(plotter.updateFunction(newPlotFunction)) { plotFunction = newPlotFunction; } @@ -115,7 +116,8 @@ public class CalculatorPlotFunctionSettingsActivity extends SherlockFragmentActi public void onItemSelected(AdapterView parent, View view, int position, long id) { final PlotLineColorType newPlotLineColorType = PlotLineColorType.values()[position]; if ( newPlotLineColorType != plotFunction.getPlotLineDef().getLineColorType() ) { - final PlotFunction newPlotFunction = new PlotFunction(plotFunction.getXyFunction(), PlotLineDef.changeLineColorType(plotFunction.getPlotLineDef(), newPlotLineColorType)); + final PlotLineDef newPlotLineDef = PlotLineDef.changeLineColorType(plotFunction.getPlotLineDef(), newPlotLineColorType); + final PlotFunction newPlotFunction = PlotFunction.changePlotLineDef(plotFunction, newPlotLineDef); if(plotter.updateFunction(newPlotFunction)) { plotFunction = newPlotFunction; } @@ -133,7 +135,10 @@ public class CalculatorPlotFunctionSettingsActivity extends SherlockFragmentActi public void onItemSelected(AdapterView parent, View view, int position, long id) { final PlotLineStyle newPlotLineStyle = PlotLineStyle.values()[position]; if ( newPlotLineStyle != plotFunction.getPlotLineDef().getLineStyle() ) { - final PlotFunction newPlotFunction = new PlotFunction(plotFunction.getXyFunction(), PlotLineDef.changeLineStyle(plotFunction.getPlotLineDef(), newPlotLineStyle)); + + final PlotLineDef newPlotLineDef = PlotLineDef.changeLineStyle(plotFunction.getPlotLineDef(), newPlotLineStyle); + final PlotFunction newPlotFunction = PlotFunction.changePlotLineDef(plotFunction, newPlotLineDef); + if(plotter.updateFunction(newPlotFunction)) { plotFunction = newPlotFunction; } diff --git a/core/src/main/java/org/solovyev/android/calculator/plot/PlotFunction.java b/core/src/main/java/org/solovyev/android/calculator/plot/PlotFunction.java index 25fab115..1b462633 100644 --- a/core/src/main/java/org/solovyev/android/calculator/plot/PlotFunction.java +++ b/core/src/main/java/org/solovyev/android/calculator/plot/PlotFunction.java @@ -13,7 +13,7 @@ public class PlotFunction { private XyFunction xyFunction; @NotNull - private PlotLineDef mPlotLineDef; + private PlotLineDef plotLineDef; private boolean pinned = false; @@ -21,26 +21,34 @@ public class PlotFunction { public PlotFunction(@NotNull XyFunction xyFunction) { this.xyFunction = xyFunction; - this.mPlotLineDef = PlotLineDef.newDefaultInstance(); + this.plotLineDef = PlotLineDef.newDefaultInstance(); } public PlotFunction(@NotNull XyFunction xyFunction, @NotNull PlotLineDef plotLineDef) { this.xyFunction = xyFunction; - this.mPlotLineDef = plotLineDef; + this.plotLineDef = plotLineDef; } @NotNull private PlotFunction copy() { final PlotFunction copy = new PlotFunction(this.xyFunction); - copy.mPlotLineDef = this.mPlotLineDef; + copy.plotLineDef = this.plotLineDef; copy.pinned = this.pinned; copy.visible = this.visible; return copy; } + @NotNull + public static PlotFunction changePlotLineDef(@NotNull PlotFunction that, @NotNull PlotLineDef newPlotLineDef) { + final PlotFunction copy = that.copy(); + copy.plotLineDef = newPlotLineDef; + return copy; + } + + @NotNull public static PlotFunction pin(@NotNull PlotFunction that) { return togglePinned(that, true); } @@ -81,7 +89,7 @@ public class PlotFunction { @NotNull public PlotLineDef getPlotLineDef() { - return mPlotLineDef; + return plotLineDef; } public boolean isPinned() {