From fa7727d66686daa86c0cb308480f4bf9d6084865 Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Mon, 21 Jan 2013 01:26:54 +0400 Subject: [PATCH] plot changes --- .../res/values-ru/text_strings.xml | 2 + .../plot/AndroidCalculatorPlotter.java | 10 ++-- .../plot/AbstractCalculatorPlotFragment.java | 54 +++++++++---------- .../plot/CalculatorGraph3dView.java | 3 +- .../calculator/plot/CalculatorPlotter.java | 2 +- .../plot/CalculatorPlotterImpl.java | 21 ++++---- 6 files changed, 49 insertions(+), 43 deletions(-) diff --git a/android-app-core/res/values-ru/text_strings.xml b/android-app-core/res/values-ru/text_strings.xml index 071f70d8..db095c87 100644 --- a/android-app-core/res/values-ru/text_strings.xml +++ b/android-app-core/res/values-ru/text_strings.xml @@ -317,6 +317,8 @@ Интервал построения X мин X макс + Y мин + Y макс Неправильное число! Границы графика не могут быть равны! Применить diff --git a/android-app-core/src/main/java/org/solovyev/android/calculator/plot/AndroidCalculatorPlotter.java b/android-app-core/src/main/java/org/solovyev/android/calculator/plot/AndroidCalculatorPlotter.java index 3bd15e5c..f63d9c2b 100644 --- a/android-app-core/src/main/java/org/solovyev/android/calculator/plot/AndroidCalculatorPlotter.java +++ b/android-app-core/src/main/java/org/solovyev/android/calculator/plot/AndroidCalculatorPlotter.java @@ -158,6 +158,11 @@ public class AndroidCalculatorPlotter implements CalculatorPlotter, SharedPrefer plotter.setPlotImag(plotImag); } + @Override + public void savePlotBoundaries(@NotNull PlotBoundaries plotBoundaries) { + plotter.savePlotBoundaries(plotBoundaries); + } + @Override public void setPlotBoundaries(@NotNull PlotBoundaries plotBoundaries) { plotter.setPlotBoundaries(plotBoundaries); @@ -169,9 +174,4 @@ public class AndroidCalculatorPlotter implements CalculatorPlotter, SharedPrefer setPlotImag(CalculatorPreferences.Graph.plotImag.getPreference(preferences)); } } - - @Override - public void setPlotData(boolean plot3d, @NotNull PlotBoundaries plotBoundaries) { - plotter.setPlotData(plot3d, plotBoundaries); - } } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/plot/AbstractCalculatorPlotFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/AbstractCalculatorPlotFragment.java index 952d483d..f79b4726 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/plot/AbstractCalculatorPlotFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/plot/AbstractCalculatorPlotFragment.java @@ -95,8 +95,11 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment setHasOptionsMenu(true); } - private void saveBoundaries(@NotNull PlotBoundaries boundaries) { - Locator.getInstance().getPlotter().setPlotBoundaries(boundaries); + private void savePlotBoundaries() { + final PlotBoundaries plotBoundaries = getPlotBoundaries(); + if (plotBoundaries != null) { + Locator.getInstance().getPlotter().savePlotBoundaries(plotBoundaries); + } } @Nullable @@ -106,10 +109,7 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment public void onPause() { PreferenceManager.getDefaultSharedPreferences(this.getActivity()).unregisterOnSharedPreferenceChangeListener(this); - final PlotBoundaries plotBoundaries = getPlotBoundaries(); - if (plotBoundaries != null) { - saveBoundaries(plotBoundaries); - } + savePlotBoundaries(); super.onPause(); } @@ -203,10 +203,25 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment super.onCreateOptionsMenu(menu, inflater); final List> menuItems = new ArrayList>(); - menuItems.add(PlotMenu.range); menuItems.add(PlotMenu.preferences); menuItems.add(PlotMenu.functions); + final IdentifiableMenuItem plotRangeMenuItem = new IdentifiableMenuItem() { + @NotNull + @Override + public Integer getItemId() { + return R.id.menu_plot_range; + } + + @Override + public void onClick(@NotNull MenuItem data, @NotNull Context context) { + savePlotBoundaries(); + + context.startActivity(new Intent(context, CalculatorPlotRangeActivity.class)); + } + }; + menuItems.add(plotRangeMenuItem); + final IdentifiableMenuItem plot3dMenuItem = new IdentifiableMenuItem() { @NotNull @Override @@ -216,13 +231,9 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment @Override public void onClick(@NotNull MenuItem data, @NotNull Context context) { - final PlotBoundaries plotBoundaries = getPlotBoundaries(); + savePlotBoundaries(); - if (plotBoundaries != null) { - Locator.getInstance().getPlotter().setPlotData(true, plotBoundaries); - } else { - Locator.getInstance().getPlotter().setPlot3d(true); - } + Locator.getInstance().getPlotter().setPlot3d(true); } }; menuItems.add(plot3dMenuItem); @@ -237,13 +248,9 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment @Override public void onClick(@NotNull MenuItem data, @NotNull Context context) { - final PlotBoundaries plotBoundaries = getPlotBoundaries(); + savePlotBoundaries(); - if (plotBoundaries != null) { - Locator.getInstance().getPlotter().setPlotData(false, plotBoundaries); - } else { - Locator.getInstance().getPlotter().setPlot3d(false); - } + Locator.getInstance().getPlotter().setPlot3d(false); } }; menuItems.add(plot2dMenuItem); @@ -275,7 +282,7 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment return !plot2dVisible; } else if ( menuItem == captureScreenshotMenuItem ) { return !captureScreenshotVisible; - } else if ( menuItem == PlotMenu.range ) { + } else if ( menuItem == plotRangeMenuItem ) { return !plotRangeVisible; } @@ -343,13 +350,6 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment private static enum PlotMenu implements IdentifiableMenuItem { - range(R.id.menu_plot_range) { - @Override - public void onClick(@NotNull MenuItem data, @NotNull Context context) { - context.startActivity(new Intent(context, CalculatorPlotRangeActivity.class)); - } - }, - functions(R.id.menu_plot_functions) { @Override public void onClick(@NotNull MenuItem data, @NotNull Context context) { diff --git a/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorGraph3dView.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorGraph3dView.java index d6c0efb1..a238a122 100755 --- a/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorGraph3dView.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorGraph3dView.java @@ -167,7 +167,8 @@ public class CalculatorGraph3dView extends GLView implements GraphView { @Override public void setXRange(float xMin, float xMax) { - dimensions.setRanges(1, 1, 1, 1); + dimensions.setXRange(PlotBoundaries.DEFAULT_MIN_NUMBER, PlotBoundaries.DEFAULT_MAX_NUMBER); + dimensions.setXY(dimensions.getX0(), 0); zoomLevel = 1; dirty = true; diff --git a/core/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotter.java b/core/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotter.java index 5a49f645..706428f8 100644 --- a/core/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotter.java +++ b/core/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotter.java @@ -58,11 +58,11 @@ public interface CalculatorPlotter { boolean isPlotPossibleFor(@NotNull Generic expression); void setPlot3d(boolean plot3d); - void setPlotData(boolean plot3d, @NotNull PlotBoundaries plotBoundaries); void removeAllUnpinned(); void setPlotImag(boolean plotImag); + void savePlotBoundaries(@NotNull PlotBoundaries plotBoundaries); void setPlotBoundaries(@NotNull PlotBoundaries plotBoundaries); } diff --git a/core/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotterImpl.java b/core/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotterImpl.java index 8a787e2f..a334de9d 100644 --- a/core/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotterImpl.java +++ b/core/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotterImpl.java @@ -372,18 +372,13 @@ public class CalculatorPlotterImpl implements CalculatorPlotter { } } - @Override - public void setPlotData(boolean plot3d, @NotNull PlotBoundaries plotBoundaries) { - if (this.plot3d != plot3d || this.plotBoundaries.equals(plotBoundaries)) { - this.plot3d = plot3d; - this.plotBoundaries = plotBoundaries; - firePlotDataChangedEvent(); - } + private void firePlotDataChangedEvent() { + updatePlotData(); + calculator.fireCalculatorEvent(CalculatorEventType.plot_data_changed, plotData); } - private void firePlotDataChangedEvent() { + private void updatePlotData() { plotData = new PlotData(getVisibleFunctions(), plot3d, plotBoundaries); - calculator.fireCalculatorEvent(CalculatorEventType.plot_data_changed, plotData); } @Override @@ -396,6 +391,14 @@ public class CalculatorPlotterImpl implements CalculatorPlotter { } } + @Override + public void savePlotBoundaries(@NotNull PlotBoundaries plotBoundaries) { + if ( !this.plotBoundaries.equals(plotBoundaries) ) { + this.plotBoundaries = plotBoundaries; + updatePlotData(); + } + } + @Override public void setPlotBoundaries(@NotNull PlotBoundaries plotBoundaries) { if ( !this.plotBoundaries.equals(plotBoundaries) ) {