new plotter
This commit is contained in:
parent
e321155585
commit
220952ef9b
@ -313,6 +313,10 @@
|
||||
<string name="cpp_plot_button_text">+plot</string>
|
||||
<string name="cpp_plot_empty_function_error">Unable to plot empty function!</string>
|
||||
<string name="cpp_plot_too_many_variables">Unable to plot: too many variables!</string>
|
||||
<string name="cpp_plot_range">Graph range</string>
|
||||
<string name="cpp_plot_range_x_min">X Min</string>
|
||||
<string name="cpp_plot_range_x_max">X Max</string>
|
||||
<string name="cpp_invalid_number">Invalid number!</string>
|
||||
|
||||
|
||||
</resources>
|
37
android-app/res/layout/cpp_plot_range_fragment.xml
Normal file
37
android-app/res/layout/cpp_plot_range_fragment.xml
Normal file
@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:id="@+id/main_fragment_layout"
|
||||
style="?cpp_fragment_layout_style"
|
||||
a:layout_width="wrap_content"
|
||||
a:layout_gravity="center_horizontal"
|
||||
a:layout_height="match_parent"
|
||||
a:orientation="vertical">
|
||||
|
||||
<include layout="@layout/ad" />
|
||||
|
||||
<TextView a:text="@string/cpp_plot_range_x_min"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"/>
|
||||
|
||||
<EditText a:id="@+id/cpp_plot_range_x_min_editext"
|
||||
a:inputType="numberDecimal"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"/>
|
||||
|
||||
<TextView a:text="@string/cpp_plot_range_x_max"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"/>
|
||||
|
||||
<EditText a:id="@+id/cpp_plot_range_x_max_editext"
|
||||
a:inputType="numberDecimal"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"/>
|
||||
|
||||
|
||||
<Button a:id="@+id/cpp_ok_button"
|
||||
a:text="@string/ok"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"/>
|
||||
|
||||
</LinearLayout>
|
@ -16,6 +16,7 @@ import org.solovyev.android.calculator.matrix.CalculatorMatrixEditFragment;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotFragment;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotFunctionSettingsActivity;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotFunctionsActivity;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotRangeActivity;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
@ -35,6 +36,7 @@ public enum CalculatorFragmentType {
|
||||
plotter(CalculatorPlotFragment.class, R.layout.cpp_plot_fragment, R.string.c_graph),
|
||||
plotter_functions(CalculatorPlotFunctionsActivity.CalculatorPlotFunctionsFragment.class, R.layout.cpp_plot_functions_fragment, R.string.cpp_plot_functions),
|
||||
plotter_function_settings(CalculatorPlotFunctionSettingsActivity.CalculatorPlotFunctionSettingsFragment.class, R.layout.cpp_plot_function_settings_fragment, R.string.cpp_plot_function_settings),
|
||||
plotter_range(CalculatorPlotRangeActivity.CalculatorPlotRangeFragment.class, R.layout.cpp_plot_range_fragment, R.string.cpp_plot_range),
|
||||
|
||||
about(CalculatorAboutFragment.class, R.layout.about_fragment, R.string.c_about),
|
||||
faq(CalculatorHelpFaqFragment.class, R.layout.help_faq_fragment, R.string.c_faq),
|
||||
|
@ -4,7 +4,6 @@ import android.os.Bundle;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.CalculatorListFragment;
|
||||
@ -26,16 +25,13 @@ public class CalculatorPlotFunctionsActivity extends SherlockFragmentActivity {
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.cpp_plot_functions_dialog);
|
||||
setContentView(R.layout.cpp_dialog);
|
||||
|
||||
FragmentUtils.createFragment(this, CalculatorPlotFunctionsFragment.class, R.id.dialog_layout, "plot-functions");
|
||||
}
|
||||
|
||||
public static class CalculatorPlotFunctionsFragment extends CalculatorListFragment {
|
||||
|
||||
@NotNull
|
||||
public static final String INPUT = "plot_input";
|
||||
|
||||
public CalculatorPlotFunctionsFragment() {
|
||||
super(CalculatorFragmentType.plotter_functions);
|
||||
}
|
||||
|
@ -0,0 +1,107 @@
|
||||
package org.solovyev.android.calculator.plot;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.CalculatorListFragment;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.fragments.FragmentUtils;
|
||||
import org.solovyev.common.msg.MessageType;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 1/19/13
|
||||
* Time: 5:14 PM
|
||||
*/
|
||||
public class CalculatorPlotRangeActivity extends SherlockFragmentActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.cpp_dialog);
|
||||
|
||||
FragmentUtils.createFragment(this, CalculatorPlotRangeFragment.class, R.id.dialog_layout, "plot-range");
|
||||
}
|
||||
|
||||
public static class CalculatorPlotRangeFragment extends CalculatorListFragment {
|
||||
|
||||
public CalculatorPlotRangeFragment() {
|
||||
super(CalculatorFragmentType.plotter_range);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NotNull View root, Bundle savedInstanceState) {
|
||||
super.onViewCreated(root, savedInstanceState);
|
||||
|
||||
final CalculatorPlotter plotter = Locator.getInstance().getPlotter();
|
||||
|
||||
final EditText xMinEditText = (EditText) root.findViewById(R.id.cpp_plot_range_x_min_editext);
|
||||
final EditText xMaxEditText = (EditText) root.findViewById(R.id.cpp_plot_range_x_max_editext);
|
||||
|
||||
final PlotData plotData = plotter.getPlotData();
|
||||
final PlotBoundaries boundaries = plotData.getBoundaries();
|
||||
|
||||
xMinEditText.setText(String.valueOf(boundaries.getXMin()));
|
||||
xMaxEditText.setText(String.valueOf(boundaries.getXMax()));
|
||||
|
||||
xMinEditText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
try {
|
||||
final Float newXMin = Float.valueOf(s.toString());
|
||||
plotter.setPlotBoundaries(PlotBoundaries.newInstance(newXMin, boundaries.getXMax()));
|
||||
} catch (NumberFormatException e) {
|
||||
Locator.getInstance().getNotifier().showMessage(R.string.cpp_invalid_number, MessageType.error);
|
||||
xMinEditText.setText(String.valueOf(boundaries.getXMin()));
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
xMaxEditText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
try {
|
||||
final Float newXMax = Float.valueOf(s.toString());
|
||||
plotter.setPlotBoundaries(PlotBoundaries.newInstance(boundaries.getXMin(), newXMax));
|
||||
} catch (NumberFormatException e) {
|
||||
Locator.getInstance().getNotifier().showMessage(R.string.cpp_invalid_number, MessageType.error);
|
||||
xMaxEditText.setText(String.valueOf(boundaries.getXMax()));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
root.findViewById(R.id.cpp_ok_button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
CalculatorPlotRangeFragment.this.getActivity().finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import org.solovyev.android.calculator.CalculatorUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -38,6 +39,9 @@ public class CalculatorPlotterImpl implements CalculatorPlotter {
|
||||
@NotNull
|
||||
private PlotBoundaries plotBoundaries = PlotBoundaries.newDefaultInstance();
|
||||
|
||||
@NotNull
|
||||
private PlotData plotData = new PlotData(Collections.<PlotFunction>emptyList(), plot3d, plotBoundaries);
|
||||
|
||||
public CalculatorPlotterImpl(@NotNull Calculator calculator) {
|
||||
this.calculator = calculator;
|
||||
}
|
||||
@ -45,7 +49,7 @@ public class CalculatorPlotterImpl implements CalculatorPlotter {
|
||||
@NotNull
|
||||
@Override
|
||||
public PlotData getPlotData() {
|
||||
return new PlotData(getVisibleFunctions(), plot3d, plotBoundaries);
|
||||
return plotData;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -369,7 +373,8 @@ public class CalculatorPlotterImpl implements CalculatorPlotter {
|
||||
}
|
||||
|
||||
private void firePlotDataChangedEvent() {
|
||||
calculator.fireCalculatorEvent(CalculatorEventType.plot_data_changed, getPlotData());
|
||||
plotData = new PlotData(getVisibleFunctions(), plot3d, plotBoundaries);
|
||||
calculator.fireCalculatorEvent(CalculatorEventType.plot_data_changed, plotData);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user