This commit is contained in:
Sergey Solovyev 2012-10-05 22:08:37 +04:00
parent c1a65f4aad
commit 638ee2e851
13 changed files with 405 additions and 392 deletions

View File

@ -123,7 +123,7 @@
<dependency> <dependency>
<groupId>achartengine</groupId> <groupId>achartengine</groupId>
<artifactId>achartengine</artifactId> <artifactId>achartengine</artifactId>
<version>0.7.0</version> <version>0.7.1</version>
</dependency> </dependency>
<dependency> <dependency>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

@ -15,6 +15,6 @@
--> -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#393939"/> <solid android:color="@color/metro_light_button_background"/>
<corners android:radius="1dp" /> <corners android:radius="1dp" />
</shape> </shape>

View File

@ -1,5 +1,7 @@
<resources> <resources>
<dimen name="fragment_text_size">10sp</dimen> <dimen name="fragment_text_size">10sp</dimen>
<dimen name="fragment_title_text_size">20sp</dimen>
<dimen name="editor_text_size">15sp</dimen> <dimen name="editor_text_size">15sp</dimen>
<dimen name="display_text_size">15sp</dimen> <dimen name="display_text_size">15sp</dimen>
<dimen name="keyboard_button_text_size">20dp</dimen> <dimen name="keyboard_button_text_size">20dp</dimen>

View File

@ -0,0 +1,9 @@
<resources>
<dimen name="fragment_text_size">20sp</dimen>
<dimen name="fragment_title_text_size">30sp</dimen>
<dimen name="editor_text_size">30sp</dimen>
<dimen name="display_text_size">30sp</dimen>
<dimen name="keyboard_button_text_size">40dp</dimen>
<dimen name="math_entity_text_size">30sp</dimen>
<dimen name="math_entity_description_text_size">20sp</dimen>
</resources>

View File

@ -18,4 +18,5 @@
<color name="metro_blue_color">#10648c</color> <color name="metro_blue_color">#10648c</color>
<color name="metro_green_color">#088e3a</color> <color name="metro_green_color">#088e3a</color>
<color name="metro_purple_color">#651456</color> <color name="metro_purple_color">#651456</color>
<color name="metro_light_button_background">#393939</color>
</resources> </resources>

View File

@ -1,7 +1,10 @@
<resources> <resources>
<dimen name="button_margin">0.5dp</dimen> <dimen name="button_margin">0.5dp</dimen>
<dimen name="text_size">20sp</dimen> <dimen name="text_size">20sp</dimen>
<dimen name="fragment_text_size">15sp</dimen> <dimen name="fragment_text_size">15sp</dimen>
<dimen name="fragment_title_text_size">20sp</dimen>
<dimen name="keyboard_button_text_size">30dp</dimen> <dimen name="keyboard_button_text_size">30dp</dimen>
<dimen name="button_text_size">20dp</dimen> <dimen name="button_text_size">20dp</dimen>
<dimen name="display_text_size">25sp</dimen> <dimen name="display_text_size">25sp</dimen>

View File

@ -37,7 +37,7 @@
<style name="default_fragment_title_style"> <style name="default_fragment_title_style">
<item name="android:textColor">@android:color/white</item> <item name="android:textColor">@android:color/white</item>
<item name="android:textSize">20sp</item> <item name="android:textSize">@dimen/fragment_title_text_size</item>
</style> </style>
<style name="default_button_style" parent="button_style"> <style name="default_button_style" parent="button_style">

View File

@ -171,6 +171,8 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
//noinspection ConstantConditions //noinspection ConstantConditions
this.chart = PlotUtils.prepareChart(getMinValue(null), getMaxValue(null), preparedInput.getExpression(), preparedInput.getVariable(), bgColor, interpolate, realLineColor.getColor(), imagLineColor.getColor()); this.chart = PlotUtils.prepareChart(getMinValue(null), getMaxValue(null), preparedInput.getExpression(), preparedInput.getVariable(), bgColor, interpolate, realLineColor.getColor(), imagLineColor.getColor());
} else {
this.chart = null;
} }
} }
@ -203,6 +205,12 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
} }
private void createGraphicalView(@NotNull View root, @Nullable PlotBoundaries plotBoundaries) { private void createGraphicalView(@NotNull View root, @Nullable PlotBoundaries plotBoundaries) {
final ViewGroup graphContainer = (ViewGroup) root.findViewById(R.id.main_fragment_layout);
if (graphicalView != null) {
graphContainer.removeView(graphicalView);
}
if (!preparedInput.isError()) { if (!preparedInput.isError()) {
final XYChart chart = this.chart; final XYChart chart = this.chart;
assert chart != null; assert chart != null;
@ -210,12 +218,6 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
double minValue = getMinValue(plotBoundaries); double minValue = getMinValue(plotBoundaries);
double maxValue = getMaxValue(plotBoundaries); double maxValue = getMaxValue(plotBoundaries);
final ViewGroup graphContainer = (ViewGroup) root.findViewById(R.id.main_fragment_layout);
if (graphicalView != null) {
graphContainer.removeView(graphicalView);
}
// reverting boundaries (as in prepareChart() we add some cached values ) // reverting boundaries (as in prepareChart() we add some cached values )
double minX = Double.MAX_VALUE; double minX = Double.MAX_VALUE;
double minY = Double.MAX_VALUE; double minY = Double.MAX_VALUE;
@ -260,7 +262,6 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
graphicalView.addPanListener(new PanListener() { graphicalView.addPanListener(new PanListener() {
@Override @Override
public void panApplied() { public void panApplied() {
Log.d(TAG, "org.achartengine.tools.PanListener.panApplied");
updateDataSets(chart); updateDataSets(chart);
} }
@ -269,7 +270,7 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
updateDataSets(chart, 50); updateDataSets(chart, 50);
} else { } else {
Toast.makeText(this.getActivity(), "Plot is not possible!", Toast.LENGTH_LONG).show(); graphicalView = null;
} }
} }
@ -294,56 +295,54 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
final Generic expression = preparedInput.getExpression(); final Generic expression = preparedInput.getExpression();
final Constant variable = preparedInput.getVariable(); final Constant variable = preparedInput.getVariable();
pendingOperation.setObject(new Runnable() { if (expression != null && variable != null) {
@Override pendingOperation.setObject(new Runnable() {
public void run() { @Override
// allow only one runner at one time public void run() {
synchronized (pendingOperation) { // allow only one runner at one time
//lock all operations with history synchronized (pendingOperation) {
if (pendingOperation.getObject() == this) { //lock all operations with history
if (pendingOperation.getObject() == this) {
plotExecutor.execute(new Runnable() { plotExecutor.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
Log.d(TAG, "org.solovyev.android.calculator.plot.CalculatorPlotActivity.updateDataSets"); final XYMultipleSeriesRenderer dr = chart.getRenderer();
final XYMultipleSeriesRenderer dr = chart.getRenderer(); final MyXYSeries realSeries = (MyXYSeries) chart.getDataset().getSeriesAt(0);
//Log.d(CalculatorPlotActivity.class.getName(), "x = [" + dr.getXAxisMin() + ", " + dr.getXAxisMax() + "], y = [" + dr.getYAxisMin() + ", " + dr.getYAxisMax() + "]"); final MyXYSeries imagSeries;
if (chart.getDataset().getSeriesCount() > 1) {
imagSeries = (MyXYSeries) chart.getDataset().getSeriesAt(1);
} else {
imagSeries = new MyXYSeries(PlotUtils.getImagFunctionName(variable), PlotUtils.DEFAULT_NUMBER_OF_STEPS * 2);
}
final MyXYSeries realSeries = (MyXYSeries) chart.getDataset().getSeriesAt(0); try {
if (PlotUtils.addXY(dr.getXAxisMin(), dr.getXAxisMax(), expression, variable, realSeries, imagSeries, true, PlotUtils.DEFAULT_NUMBER_OF_STEPS)) {
final MyXYSeries imagSeries; if (chart.getDataset().getSeriesCount() <= 1) {
if (chart.getDataset().getSeriesCount() > 1) { chart.getDataset().addSeries(imagSeries);
imagSeries = (MyXYSeries) chart.getDataset().getSeriesAt(1); chart.getRenderer().addSeriesRenderer(PlotUtils.createImagRenderer(imagLineColor.getColor()));
} else { }
imagSeries = new MyXYSeries(PlotUtils.getImagFunctionName(variable), PlotUtils.DEFAULT_NUMBER_OF_STEPS * 2);
}
try {
if (PlotUtils.addXY(dr.getXAxisMin(), dr.getXAxisMax(), expression, variable, realSeries, imagSeries, true, PlotUtils.DEFAULT_NUMBER_OF_STEPS)) {
if (chart.getDataset().getSeriesCount() <= 1) {
chart.getDataset().addSeries(imagSeries);
chart.getRenderer().addSeriesRenderer(PlotUtils.createImagRenderer(imagLineColor.getColor()));
} }
} catch (ArithmeticException e) {
// todo serso: translate
Toast.makeText(CalculatorPlotFragment.this.getActivity(), "Arithmetic error: " + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
} }
} catch (ArithmeticException e) {
// todo serso: translate
Toast.makeText(CalculatorPlotFragment.this.getActivity(), "Arithmetic error: " + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
uiHandler.post(new Runnable() { uiHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
graphicalView.repaint(); graphicalView.repaint();
} }
}); });
} }
}); });
}
} }
} }
} });
}); }
uiHandler.postDelayed(pendingOperation.getObject(), millisToWait); uiHandler.postDelayed(pendingOperation.getObject(), millisToWait);

View File

@ -9,8 +9,7 @@ package org.solovyev.android.calculator.plot;
import org.achartengine.model.XYSeries; import org.achartengine.model.XYSeries;
import org.achartengine.util.MathHelper; import org.achartengine.util.MathHelper;
import java.util.ArrayList; import java.util.*;
import java.util.List;
/** /**
* User: serso * User: serso