new plotter

This commit is contained in:
Sergey Solovyev
2013-01-14 14:00:21 +04:00
parent bb9d6f4038
commit 400d5003a3
57 changed files with 625 additions and 271 deletions

View File

@@ -7,7 +7,7 @@ import org.jetbrains.annotations.NotNull;
import org.solovyev.android.AndroidUtils;
import org.solovyev.android.calculator.math.MathType;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
import org.solovyev.android.calculator.plot.GraphLineColor;
import org.solovyev.android.calculator.plot.PlotLineColor;
import org.solovyev.android.prefs.BooleanPreference;
import org.solovyev.android.prefs.IntegerPreference;
import org.solovyev.android.prefs.LongPreference;
@@ -132,8 +132,8 @@ public final class CalculatorPreferences {
public static class Graph {
public static final Preference<Boolean> interpolate = new BooleanPreference("graph_interpolate", true);
public static final Preference<GraphLineColor> lineColorReal = StringPreference.newInstance("graph_line_color_real", GraphLineColor.white, GraphLineColor.class);
public static final Preference<GraphLineColor> lineColorImag = StringPreference.newInstance("graph_line_color_imag", GraphLineColor.blue, GraphLineColor.class);
public static final Preference<PlotLineColor> lineColorReal = StringPreference.newInstance("graph_line_color_real", PlotLineColor.white, PlotLineColor.class);
public static final Preference<PlotLineColor> lineColorImag = StringPreference.newInstance("graph_line_color_imag", PlotLineColor.blue, PlotLineColor.class);
public static final Preference<Boolean> plotImag = new BooleanPreference("graph_plot_imag", false);
}

View File

@@ -5,6 +5,7 @@ import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import jscl.math.Generic;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorPreferences;
import java.util.List;
@@ -53,7 +54,7 @@ public class AndroidCalculatorPlotter implements CalculatorPlotter, SharedPrefer
}
@Override
public boolean addFunction(@NotNull XyFunction xyFunction, @NotNull PlotFunctionLineDef functionLineDef) {
public boolean addFunction(@NotNull XyFunction xyFunction, @NotNull PlotLineDef functionLineDef) {
return plotter.addFunction(xyFunction, functionLineDef);
}
@@ -63,7 +64,7 @@ public class AndroidCalculatorPlotter implements CalculatorPlotter, SharedPrefer
}
@Override
public boolean updateFunction(@NotNull XyFunction xyFunction, @NotNull PlotFunctionLineDef functionLineDef) {
public boolean updateFunction(@NotNull XyFunction xyFunction, @NotNull PlotLineDef functionLineDef) {
return plotter.updateFunction(xyFunction, functionLineDef);
}
@@ -106,7 +107,13 @@ public class AndroidCalculatorPlotter implements CalculatorPlotter, SharedPrefer
plotter.clearAllFunctions();
}
@Override
@Nullable
@Override
public PlotFunction getFunctionById(@NotNull String functionId) {
return plotter.getFunctionById(functionId);
}
@Override
@NotNull
public List<PlotFunction> getFunctions() {
return plotter.getFunctions();
@@ -168,11 +175,11 @@ public class AndroidCalculatorPlotter implements CalculatorPlotter, SharedPrefer
}
}
public void setImagLineColor(@NotNull GraphLineColor imagLineColor) {
public void setImagLineColor(@NotNull PlotLineColor imagLineColor) {
plotter.setImagLineColor(imagLineColor);
}
public void setRealLineColor(@NotNull GraphLineColor realLineColor) {
public void setRealLineColor(@NotNull PlotLineColor realLineColor) {
plotter.setRealLineColor(realLineColor);
}
}

View File

@@ -1,119 +0,0 @@
package org.solovyev.android.calculator.plot;
import android.content.Context;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.core.R;
import org.solovyev.android.list.ListItem;
import org.solovyev.android.view.ViewBuilder;
import org.solovyev.android.view.ViewFromLayoutBuilder;
public class PlotFunctionListItem implements ListItem {
private static final String PREFIX = "plot_function_";
@NotNull
private PlotFunction plotFunction;
@NotNull
private ViewBuilder<View> viewBuilder;
@NotNull
private String tag;
public PlotFunctionListItem(@NotNull PlotFunction plotFunction) {
this.plotFunction = plotFunction;
this.viewBuilder = ViewFromLayoutBuilder.newInstance(R.layout.cpp_plot_function_list_item);
this.tag = PREFIX + plotFunction.getXyFunction().getExpressionString();
}
@Nullable
@Override
public OnClickAction getOnClickAction() {
return null;
}
@Nullable
@Override
public OnClickAction getOnLongClickAction() {
return null;
}
@NotNull
@Override
public View updateView(@NotNull Context context, @NotNull View view) {
final Object viewTag = view.getTag();
if ( viewTag instanceof String ) {
if ( this.tag.equals(viewTag) ) {
return view;
} else if (((String) viewTag).startsWith(PREFIX)) {
fillView(view);
return view;
} else {
return build(context);
}
}
return build(context);
}
@NotNull
@Override
public View build(@NotNull Context context) {
final View root = buildView(context);
fillView(root);
return root;
}
private View buildView(@NotNull Context context) {
return viewBuilder.build(context);
}
private void fillView(@NotNull View root) {
root.setTag(tag);
final CalculatorPlotter plotter = Locator.getInstance().getPlotter();
final TextView expressionTextView = (TextView) root.findViewById(R.id.cpp_plot_function_expression_textview);
expressionTextView.setText(plotFunction.getXyFunction().getExpressionString());
final CheckBox pinnedCheckBox = (CheckBox) root.findViewById(R.id.cpp_plot_function_pinned_checkbox);
pinnedCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean pin) {
if (pin) {
if (!plotFunction.isPinned()) {
plotFunction = plotter.pin(plotFunction);
}
} else {
if (plotFunction.isPinned()) {
plotFunction = plotter.unpin(plotFunction);
}
}
}
});
pinnedCheckBox.setChecked(plotFunction.isPinned());
final CheckBox visibleCheckBox = (CheckBox) root.findViewById(R.id.cpp_plot_function_visible_checkbox);
visibleCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean show) {
if (show) {
if (!plotFunction.isVisible()) {
plotFunction = plotter.show(plotFunction);
}
} else {
if (plotFunction.isVisible()) {
plotFunction = plotter.hide(plotFunction);
}
}
}
});
visibleCheckBox.setChecked(plotFunction.isVisible());
}
}