plot changes

This commit is contained in:
Sergey Solovyev 2013-01-21 01:26:54 +04:00
parent 62eb80c89d
commit fa7727d666
6 changed files with 49 additions and 43 deletions

View File

@ -317,6 +317,8 @@
<string name="cpp_plot_range">Интервал построения</string> <string name="cpp_plot_range">Интервал построения</string>
<string name="cpp_plot_range_x_min">X мин</string> <string name="cpp_plot_range_x_min">X мин</string>
<string name="cpp_plot_range_x_max">X макс</string> <string name="cpp_plot_range_x_max">X макс</string>
<string name="cpp_plot_range_y_min">Y мин</string>
<string name="cpp_plot_range_y_max">Y макс</string>
<string name="cpp_invalid_number">Неправильное число!</string> <string name="cpp_invalid_number">Неправильное число!</string>
<string name="cpp_plot_boundaries_should_differ">Границы графика не могут быть равны!</string> <string name="cpp_plot_boundaries_should_differ">Границы графика не могут быть равны!</string>
<string name="cpp_apply">Применить</string> <string name="cpp_apply">Применить</string>

View File

@ -158,6 +158,11 @@ public class AndroidCalculatorPlotter implements CalculatorPlotter, SharedPrefer
plotter.setPlotImag(plotImag); plotter.setPlotImag(plotImag);
} }
@Override
public void savePlotBoundaries(@NotNull PlotBoundaries plotBoundaries) {
plotter.savePlotBoundaries(plotBoundaries);
}
@Override @Override
public void setPlotBoundaries(@NotNull PlotBoundaries plotBoundaries) { public void setPlotBoundaries(@NotNull PlotBoundaries plotBoundaries) {
plotter.setPlotBoundaries(plotBoundaries); plotter.setPlotBoundaries(plotBoundaries);
@ -169,9 +174,4 @@ public class AndroidCalculatorPlotter implements CalculatorPlotter, SharedPrefer
setPlotImag(CalculatorPreferences.Graph.plotImag.getPreference(preferences)); setPlotImag(CalculatorPreferences.Graph.plotImag.getPreference(preferences));
} }
} }
@Override
public void setPlotData(boolean plot3d, @NotNull PlotBoundaries plotBoundaries) {
plotter.setPlotData(plot3d, plotBoundaries);
}
} }

View File

@ -95,8 +95,11 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
setHasOptionsMenu(true); setHasOptionsMenu(true);
} }
private void saveBoundaries(@NotNull PlotBoundaries boundaries) { private void savePlotBoundaries() {
Locator.getInstance().getPlotter().setPlotBoundaries(boundaries); final PlotBoundaries plotBoundaries = getPlotBoundaries();
if (plotBoundaries != null) {
Locator.getInstance().getPlotter().savePlotBoundaries(plotBoundaries);
}
} }
@Nullable @Nullable
@ -106,10 +109,7 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
public void onPause() { public void onPause() {
PreferenceManager.getDefaultSharedPreferences(this.getActivity()).unregisterOnSharedPreferenceChangeListener(this); PreferenceManager.getDefaultSharedPreferences(this.getActivity()).unregisterOnSharedPreferenceChangeListener(this);
final PlotBoundaries plotBoundaries = getPlotBoundaries(); savePlotBoundaries();
if (plotBoundaries != null) {
saveBoundaries(plotBoundaries);
}
super.onPause(); super.onPause();
} }
@ -203,10 +203,25 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
super.onCreateOptionsMenu(menu, inflater); super.onCreateOptionsMenu(menu, inflater);
final List<IdentifiableMenuItem<MenuItem>> menuItems = new ArrayList<IdentifiableMenuItem<MenuItem>>(); final List<IdentifiableMenuItem<MenuItem>> menuItems = new ArrayList<IdentifiableMenuItem<MenuItem>>();
menuItems.add(PlotMenu.range);
menuItems.add(PlotMenu.preferences); menuItems.add(PlotMenu.preferences);
menuItems.add(PlotMenu.functions); menuItems.add(PlotMenu.functions);
final IdentifiableMenuItem<MenuItem> plotRangeMenuItem = new IdentifiableMenuItem<MenuItem>() {
@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<MenuItem> plot3dMenuItem = new IdentifiableMenuItem<MenuItem>() { final IdentifiableMenuItem<MenuItem> plot3dMenuItem = new IdentifiableMenuItem<MenuItem>() {
@NotNull @NotNull
@Override @Override
@ -216,14 +231,10 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
@Override @Override
public void onClick(@NotNull MenuItem data, @NotNull Context context) { 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); menuItems.add(plot3dMenuItem);
@ -237,14 +248,10 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
@Override @Override
public void onClick(@NotNull MenuItem data, @NotNull Context context) { 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); menuItems.add(plot2dMenuItem);
@ -275,7 +282,7 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
return !plot2dVisible; return !plot2dVisible;
} else if ( menuItem == captureScreenshotMenuItem ) { } else if ( menuItem == captureScreenshotMenuItem ) {
return !captureScreenshotVisible; return !captureScreenshotVisible;
} else if ( menuItem == PlotMenu.range ) { } else if ( menuItem == plotRangeMenuItem ) {
return !plotRangeVisible; return !plotRangeVisible;
} }
@ -343,13 +350,6 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
private static enum PlotMenu implements IdentifiableMenuItem<MenuItem> { private static enum PlotMenu implements IdentifiableMenuItem<MenuItem> {
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) { functions(R.id.menu_plot_functions) {
@Override @Override
public void onClick(@NotNull MenuItem data, @NotNull Context context) { public void onClick(@NotNull MenuItem data, @NotNull Context context) {

View File

@ -167,7 +167,8 @@ public class CalculatorGraph3dView extends GLView implements GraphView {
@Override @Override
public void setXRange(float xMin, float xMax) { 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; zoomLevel = 1;
dirty = true; dirty = true;

View File

@ -58,11 +58,11 @@ public interface CalculatorPlotter {
boolean isPlotPossibleFor(@NotNull Generic expression); boolean isPlotPossibleFor(@NotNull Generic expression);
void setPlot3d(boolean plot3d); void setPlot3d(boolean plot3d);
void setPlotData(boolean plot3d, @NotNull PlotBoundaries plotBoundaries);
void removeAllUnpinned(); void removeAllUnpinned();
void setPlotImag(boolean plotImag); void setPlotImag(boolean plotImag);
void savePlotBoundaries(@NotNull PlotBoundaries plotBoundaries);
void setPlotBoundaries(@NotNull PlotBoundaries plotBoundaries); void setPlotBoundaries(@NotNull PlotBoundaries plotBoundaries);
} }

View File

@ -372,18 +372,13 @@ public class CalculatorPlotterImpl implements CalculatorPlotter {
} }
} }
@Override private void firePlotDataChangedEvent() {
public void setPlotData(boolean plot3d, @NotNull PlotBoundaries plotBoundaries) { updatePlotData();
if (this.plot3d != plot3d || this.plotBoundaries.equals(plotBoundaries)) { calculator.fireCalculatorEvent(CalculatorEventType.plot_data_changed, plotData);
this.plot3d = plot3d;
this.plotBoundaries = plotBoundaries;
firePlotDataChangedEvent();
}
} }
private void firePlotDataChangedEvent() { private void updatePlotData() {
plotData = new PlotData(getVisibleFunctions(), plot3d, plotBoundaries); plotData = new PlotData(getVisibleFunctions(), plot3d, plotBoundaries);
calculator.fireCalculatorEvent(CalculatorEventType.plot_data_changed, plotData);
} }
@Override @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 @Override
public void setPlotBoundaries(@NotNull PlotBoundaries plotBoundaries) { public void setPlotBoundaries(@NotNull PlotBoundaries plotBoundaries) {
if ( !this.plotBoundaries.equals(plotBoundaries) ) { if ( !this.plotBoundaries.equals(plotBoundaries) ) {