new plotter
This commit is contained in:
@@ -23,7 +23,6 @@ import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.AndroidUtils;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.about.CalculatorReleaseNotesFragment;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotActivity;
|
||||
import org.solovyev.android.fragments.FragmentUtils;
|
||||
|
@@ -7,7 +7,6 @@ import android.view.View;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
|
@@ -19,7 +19,6 @@ import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.AndroidUtils;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener;
|
||||
|
||||
/**
|
||||
|
@@ -7,7 +7,6 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import com.actionbarsherlock.app.SherlockFragment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package org.solovyev.android.calculator.about;
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.CalculatorEditorFragment;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.about.CalculatorAboutFragment;
|
||||
import org.solovyev.android.calculator.about.CalculatorReleaseNotesFragment;
|
||||
import org.solovyev.android.calculator.help.CalculatorHelpFaqFragment;
|
||||
import org.solovyev.android.calculator.help.CalculatorHelpHintsFragment;
|
||||
import org.solovyev.android.calculator.help.CalculatorHelpScreensFragment;
|
||||
@@ -14,7 +14,8 @@ import org.solovyev.android.calculator.math.edit.CalculatorOperatorsFragment;
|
||||
import org.solovyev.android.calculator.math.edit.CalculatorVarsFragment;
|
||||
import org.solovyev.android.calculator.matrix.CalculatorMatrixEditFragment;
|
||||
import org.solovyev.android.calculator.plot.CalculatorArityPlotFragment;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotFunctionsFragment;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotFunctionSettingsActivity;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotFunctionsActivity;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
@@ -31,10 +32,12 @@ public enum CalculatorFragmentType {
|
||||
variables(CalculatorVarsFragment.class, R.layout.vars_fragment, R.string.c_vars),
|
||||
functions(CalculatorFunctionsFragment.class, R.layout.math_entities_fragment, R.string.c_functions),
|
||||
operators(CalculatorOperatorsFragment.class, R.layout.math_entities_fragment, R.string.c_operators),
|
||||
plotter(CalculatorArityPlotFragment.class, R.layout.plot_fragment, R.string.c_graph),
|
||||
plotter(CalculatorArityPlotFragment.class, R.layout.cpp_plot_fragment, R.string.c_graph),
|
||||
|
||||
// todo serso: strings
|
||||
plotter_functions(CalculatorPlotFunctionsFragment.class, R.layout.plot_functions_fragment, R.string.c_graph),
|
||||
plotter_functions(CalculatorPlotFunctionsActivity.CalculatorPlotFunctionsFragment.class, R.layout.cpp_plot_functions_fragment, R.string.c_graph),
|
||||
plotter_function_settings(CalculatorPlotFunctionSettingsActivity.CalculatorPlotFunctionSettingsFragment.class, R.layout.cpp_plot_function_settings_fragment, R.string.c_graph),
|
||||
|
||||
about(CalculatorAboutFragment.class, R.layout.about_fragment, R.string.c_about),
|
||||
faq(CalculatorHelpFaqFragment.class, R.layout.help_faq_fragment, R.string.c_faq),
|
||||
hints(CalculatorHelpHintsFragment.class, R.layout.help_hints_fragment, R.string.c_hints),
|
@@ -7,7 +7,6 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import com.actionbarsherlock.app.SherlockListFragment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
|
@@ -8,6 +8,7 @@ package org.solovyev.android.calculator.about;
|
||||
import android.os.Bundle;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentActivity;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
/**
|
||||
|
@@ -11,6 +11,7 @@ import android.text.method.LinkMovementMethod;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import org.solovyev.android.calculator.CalculatorFragment;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
/**
|
||||
|
@@ -16,6 +16,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.AndroidUtils;
|
||||
import org.solovyev.android.calculator.CalculatorApplication;
|
||||
import org.solovyev.android.calculator.CalculatorFragment;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.common.text.StringUtils;
|
||||
|
||||
|
@@ -9,8 +9,8 @@ package org.solovyev.android.calculator.help;
|
||||
import android.os.Bundle;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentActivity;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
|
@@ -7,7 +7,7 @@
|
||||
package org.solovyev.android.calculator.help;
|
||||
|
||||
import org.solovyev.android.calculator.CalculatorFragment;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
|
@@ -7,7 +7,7 @@
|
||||
package org.solovyev.android.calculator.help;
|
||||
|
||||
import org.solovyev.android.calculator.CalculatorFragment;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
|
@@ -7,7 +7,7 @@
|
||||
package org.solovyev.android.calculator.help;
|
||||
|
||||
import org.solovyev.android.calculator.CalculatorFragment;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
|
@@ -22,7 +22,7 @@ import com.actionbarsherlock.view.MenuItem;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||
import org.solovyev.android.menu.*;
|
||||
import org.solovyev.android.sherlock.menu.SherlockMenuHelper;
|
||||
|
@@ -11,7 +11,7 @@ import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
|
@@ -11,7 +11,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.CalculatorPreferences;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@@ -7,9 +7,9 @@
|
||||
package org.solovyev.android.calculator.history;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@@ -19,7 +19,7 @@ import com.actionbarsherlock.app.SherlockListFragment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.menu.AMenuBuilder;
|
||||
import org.solovyev.android.menu.AMenuItem;
|
||||
import org.solovyev.android.menu.LabeledMenuItem;
|
||||
|
@@ -13,7 +13,7 @@ import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
|
||||
|
||||
/**
|
||||
|
@@ -20,7 +20,7 @@ import jscl.math.function.IFunction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.function.FunctionEditDialogFragment;
|
||||
import org.solovyev.android.menu.AMenuItem;
|
||||
import org.solovyev.android.menu.LabeledMenuItem;
|
||||
|
@@ -11,7 +11,7 @@ import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
|
||||
|
||||
/**
|
||||
|
@@ -8,7 +8,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.CalculatorEventType;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.menu.AMenuItem;
|
||||
import org.solovyev.android.menu.LabeledMenuItem;
|
||||
import org.solovyev.common.text.StringUtils;
|
||||
|
@@ -12,7 +12,7 @@ import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
|
||||
import org.solovyev.android.calculator.AndroidVarCategory;
|
||||
import org.solovyev.android.calculator.VarCategory;
|
||||
|
@@ -17,7 +17,7 @@ import jscl.math.function.IConstant;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.math.MathType;
|
||||
import org.solovyev.android.menu.AMenuItem;
|
||||
import org.solovyev.android.menu.LabeledMenuItem;
|
||||
|
@@ -3,8 +3,8 @@ package org.solovyev.android.calculator.matrix;
|
||||
import android.app.ActionBar;
|
||||
import android.os.Bundle;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentActivity;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
|
@@ -5,8 +5,8 @@ import android.view.View;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.CalculatorFragment;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
import org.solovyev.android.view.IntegerRange;
|
||||
import org.solovyev.android.view.Picker;
|
||||
|
||||
|
@@ -80,7 +80,7 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
|
||||
|
||||
|
||||
public AbstractCalculatorPlotFragment() {
|
||||
super(CalculatorApplication.getInstance().createFragmentHelper(R.layout.plot_fragment, R.string.c_graph, false));
|
||||
super(CalculatorApplication.getInstance().createFragmentHelper(R.layout.cpp_plot_fragment, R.string.c_graph, false));
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
|
||||
plotData = Locator.getInstance().getPlotter().getPlotData();
|
||||
createChart(plotData);
|
||||
createGraphicalView(getView(), plotData);
|
||||
getActivity().invalidateOptionsMenu();
|
||||
getSherlockActivity().invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -138,7 +138,7 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
|
||||
getUiHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getActivity().invalidateOptionsMenu();
|
||||
getSherlockActivity().invalidateOptionsMenu();
|
||||
|
||||
createChart(plotData);
|
||||
|
||||
@@ -361,17 +361,17 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
|
||||
}
|
||||
}
|
||||
|
||||
public static void applyToPaint(@NotNull PlotFunctionLineDef plotFunctionLineDef, @NotNull Paint paint) {
|
||||
paint.setColor(plotFunctionLineDef.getLineColor());
|
||||
public static void applyToPaint(@NotNull PlotLineDef plotLineDef, @NotNull Paint paint) {
|
||||
paint.setColor(plotLineDef.getLineColor());
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
|
||||
if ( plotFunctionLineDef.getLineWidth() == PlotFunctionLineDef.DEFAULT_LINE_WIDTH ) {
|
||||
if ( plotLineDef.getLineWidth() == PlotLineDef.DEFAULT_LINE_WIDTH ) {
|
||||
paint.setStrokeWidth(0);
|
||||
} else {
|
||||
paint.setStrokeWidth(plotFunctionLineDef.getLineWidth());
|
||||
paint.setStrokeWidth(plotLineDef.getLineWidth());
|
||||
}
|
||||
|
||||
final AndroidPlotLineStyle androidPlotLineStyle = AndroidPlotLineStyle.valueOf(plotFunctionLineDef.getLineStyle());
|
||||
final AndroidPlotLineStyle androidPlotLineStyle = AndroidPlotLineStyle.valueOf(plotLineDef.getLineStyle());
|
||||
if (androidPlotLineStyle != null) {
|
||||
androidPlotLineStyle.applyToPaint(paint);
|
||||
}
|
||||
|
@@ -14,18 +14,18 @@ public class ArityPlotFunction {
|
||||
private Function function;
|
||||
|
||||
@NotNull
|
||||
private PlotFunctionLineDef lineDef;
|
||||
private PlotLineDef lineDef;
|
||||
|
||||
private ArityPlotFunction() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ArityPlotFunction newInstance(@NotNull Function function) {
|
||||
return newInstance(function, PlotFunctionLineDef.newDefaultInstance());
|
||||
return newInstance(function, PlotLineDef.newDefaultInstance());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ArityPlotFunction newInstance(@NotNull Function function, @NotNull PlotFunctionLineDef lineDef) {
|
||||
public static ArityPlotFunction newInstance(@NotNull Function function, @NotNull PlotLineDef lineDef) {
|
||||
final ArityPlotFunction result = new ArityPlotFunction();
|
||||
|
||||
result.function = function;
|
||||
@@ -40,7 +40,7 @@ public class ArityPlotFunction {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PlotFunctionLineDef getLineDef() {
|
||||
public PlotLineDef getLineDef() {
|
||||
return lineDef;
|
||||
}
|
||||
}
|
||||
|
@@ -54,7 +54,7 @@ public class CalculatorArityPlotFragment extends AbstractCalculatorPlotFragment
|
||||
final Constant xVariable = xyFunction.getXVariable();
|
||||
final Constant yVariable = xyFunction.getYVariable();
|
||||
|
||||
final int arity = xVariable == null ? 0 : (yVariable == null ? 1 : 2);
|
||||
final int arity = xyFunction.getArity();
|
||||
|
||||
final Function arityFunction;
|
||||
if (xyFunction.isImag()) {
|
||||
@@ -63,7 +63,7 @@ public class CalculatorArityPlotFragment extends AbstractCalculatorPlotFragment
|
||||
arityFunction = new RealArityFunction(arity, expression, xVariable, yVariable);
|
||||
}
|
||||
|
||||
arityFunctions.add(ArityPlotFunction.newInstance(arityFunction, plotFunction.getPlotFunctionLineDef()));
|
||||
arityFunctions.add(ArityPlotFunction.newInstance(arityFunction, plotFunction.getPlotLineDef()));
|
||||
}
|
||||
|
||||
if ( plotData.isPlot3d() ) {
|
||||
|
@@ -6,8 +6,8 @@ import android.os.Bundle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentActivity;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
|
@@ -0,0 +1,166 @@
|
||||
package org.solovyev.android.calculator.plot;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Button;
|
||||
import android.widget.Spinner;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.CalculatorFragment;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.fragments.FragmentUtils;
|
||||
|
||||
public class CalculatorPlotFunctionSettingsActivity extends SherlockFragmentActivity {
|
||||
|
||||
private static final String INPUT_FUNCTION_ID = "plot-function-id";
|
||||
|
||||
public static void startActivity(@NotNull Context context, @NotNull PlotFunction plotFunction) {
|
||||
final Intent intent = new Intent(context, CalculatorPlotFunctionSettingsActivity.class);
|
||||
intent.putExtra(INPUT_FUNCTION_ID, plotFunction.getXyFunction().getId());
|
||||
context.startActivity(intent);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.cpp_plot_function_settings_dialog);
|
||||
|
||||
final Intent intent = getIntent();
|
||||
|
||||
if (intent != null) {
|
||||
final String plotFunctionId = intent.getStringExtra(INPUT_FUNCTION_ID);
|
||||
|
||||
if (plotFunctionId != null) {
|
||||
final Bundle parameters = new Bundle();
|
||||
parameters.putString(INPUT_FUNCTION_ID, plotFunctionId);
|
||||
FragmentUtils.createFragment(this, CalculatorPlotFunctionSettingsFragment.class, R.id.dialog_layout, "plot-function-settings", parameters);
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
public static class CalculatorPlotFunctionSettingsFragment extends CalculatorFragment {
|
||||
|
||||
@Nullable
|
||||
private PlotFunction plotFunction;
|
||||
|
||||
public CalculatorPlotFunctionSettingsFragment() {
|
||||
super(CalculatorFragmentType.plotter_function_settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
final String functionId = getArguments().getString(INPUT_FUNCTION_ID);
|
||||
if (functionId != null) {
|
||||
plotFunction = Locator.getInstance().getPlotter().getFunctionById(functionId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return super.onCreateView(inflater, container, savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||
super.onViewCreated(root, savedInstanceState);
|
||||
|
||||
final CalculatorPlotter plotter = Locator.getInstance().getPlotter();
|
||||
|
||||
final Spinner plotLineColorSpinner = (Spinner)root.findViewById(R.id.cpp_plot_function_line_color_spinner);
|
||||
final Spinner plotLineColorTypeSpinner = (Spinner)root.findViewById(R.id.cpp_plot_function_line_color_type_spinner);
|
||||
final Spinner plotLineStyleSpinner = (Spinner)root.findViewById(R.id.cpp_plot_function_line_style_spinner);
|
||||
final Button okButton = (Button)root.findViewById(R.id.cpp_ok_button);
|
||||
|
||||
if (plotFunction != null) {
|
||||
|
||||
plotLineColorSpinner.setSelection(PlotLineColor.valueOf(plotFunction.getPlotLineDef().getLineColor()).ordinal());
|
||||
plotLineColorSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
final PlotLineColor newPlotLineColor = PlotLineColor.values()[position];
|
||||
int newLineColor = newPlotLineColor.getColor();
|
||||
if ( newLineColor != plotFunction.getPlotLineDef().getLineColor() ) {
|
||||
final PlotFunction newPlotFunction = new PlotFunction(plotFunction.getXyFunction(), PlotLineDef.changeLineColor(plotFunction.getPlotLineDef(), newLineColor));
|
||||
if(plotter.updateFunction(newPlotFunction)) {
|
||||
plotFunction = newPlotFunction;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
}
|
||||
});
|
||||
|
||||
plotLineColorTypeSpinner.setSelection(plotFunction.getPlotLineDef().getLineColorType().ordinal());
|
||||
plotLineColorTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
final PlotLineColorType newPlotLineColorType = PlotLineColorType.values()[position];
|
||||
if ( newPlotLineColorType != plotFunction.getPlotLineDef().getLineColorType() ) {
|
||||
final PlotFunction newPlotFunction = new PlotFunction(plotFunction.getXyFunction(), PlotLineDef.changeLineColorType(plotFunction.getPlotLineDef(), newPlotLineColorType));
|
||||
if(plotter.updateFunction(newPlotFunction)) {
|
||||
plotFunction = newPlotFunction;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
}
|
||||
});
|
||||
|
||||
plotLineStyleSpinner.setSelection(plotFunction.getPlotLineDef().getLineStyle().ordinal());
|
||||
plotLineStyleSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
final PlotLineStyle newPlotLineStyle = PlotLineStyle.values()[position];
|
||||
if ( newPlotLineStyle != plotFunction.getPlotLineDef().getLineStyle() ) {
|
||||
final PlotFunction newPlotFunction = new PlotFunction(plotFunction.getXyFunction(), PlotLineDef.changeLineStyle(plotFunction.getPlotLineDef(), newPlotLineStyle));
|
||||
if(plotter.updateFunction(newPlotFunction)) {
|
||||
plotFunction = newPlotFunction;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
}
|
||||
});
|
||||
|
||||
okButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final Activity activity = getActivity();
|
||||
if ( activity != null ) {
|
||||
activity.finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
plotLineColorSpinner.setEnabled(false);
|
||||
plotLineColorTypeSpinner.setEnabled(false);
|
||||
plotLineStyleSpinner.setEnabled(false);
|
||||
okButton.setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,9 +2,18 @@ package org.solovyev.android.calculator.plot;
|
||||
|
||||
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;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.fragments.FragmentUtils;
|
||||
import org.solovyev.android.list.ListItemArrayAdapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
@@ -21,4 +30,29 @@ public class CalculatorPlotFunctionsActivity extends SherlockFragmentActivity {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
final List<PlotFunctionListItem> items = Lists.transform(Locator.getInstance().getPlotter().getFunctions(), new Function<PlotFunction, PlotFunctionListItem>() {
|
||||
@Override
|
||||
public PlotFunctionListItem apply(@javax.annotation.Nullable PlotFunction input) {
|
||||
assert input != null;
|
||||
return new PlotFunctionListItem(input);
|
||||
}
|
||||
});
|
||||
|
||||
ListItemArrayAdapter.createAndAttach(getListView(), this.getActivity(), items);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,37 +0,0 @@
|
||||
package org.solovyev.android.calculator.plot;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.CalculatorListFragment;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
import org.solovyev.android.list.ListItemArrayAdapter;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class CalculatorPlotFunctionsFragment extends CalculatorListFragment {
|
||||
|
||||
@NotNull
|
||||
public static final String INPUT = "plot_input";
|
||||
|
||||
public CalculatorPlotFunctionsFragment() {
|
||||
super(CalculatorFragmentType.plotter_functions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
final List<PlotFunctionListItem> items = Lists.transform(Locator.getInstance().getPlotter().getFunctions(), new Function<PlotFunction, PlotFunctionListItem>() {
|
||||
@Override
|
||||
public PlotFunctionListItem apply(@Nullable PlotFunction input) {
|
||||
assert input != null;
|
||||
return new PlotFunctionListItem(input);
|
||||
}
|
||||
});
|
||||
|
||||
ListItemArrayAdapter.createAndAttach(getListView(), this.getActivity(), items);
|
||||
}
|
||||
}
|
@@ -94,7 +94,7 @@ class Graph3d {
|
||||
|
||||
public void update(@NotNull GL11 gl, @NotNull ArityPlotFunction fpd, float zoom) {
|
||||
final Function function = fpd.getFunction();
|
||||
final PlotFunctionLineDef lineDef = fpd.getLineDef();
|
||||
final PlotLineDef lineDef = fpd.getLineDef();
|
||||
final int NTICK = useHighQuality3d ? 5 : 0;
|
||||
|
||||
final float size = 4 * zoom;
|
||||
@@ -285,7 +285,7 @@ class Graph3d {
|
||||
return maxAbsZ;
|
||||
}
|
||||
|
||||
private byte[] prepareFunctionPolygonColors(PlotFunctionLineDef lineDef, float[] vertices, float maxAbsZ) {
|
||||
private byte[] prepareFunctionPolygonColors(PlotLineDef lineDef, float[] vertices, float maxAbsZ) {
|
||||
// 4 color components per polygon (color[i] = red, color[i+1] = green, color[i+2] = blue, color[i+3] = alpha )
|
||||
final byte colors[] = new byte[polygonsⁿ * COLOR_COMPONENTS_COUNT];
|
||||
|
||||
@@ -295,7 +295,7 @@ class Graph3d {
|
||||
final float z = vertices[j];
|
||||
|
||||
if (!Float.isNaN(z)) {
|
||||
if (lineDef.getLineColorType() == PlotFunctionLineColorType.color_map) {
|
||||
if (lineDef.getLineColorType() == PlotLineColorType.color_map) {
|
||||
final float color = z / maxAbsZ;
|
||||
final float abs = Math.abs(color);
|
||||
colors[i] = floatToByte(color);
|
||||
|
@@ -0,0 +1,128 @@
|
||||
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.ImageButton;
|
||||
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, context);
|
||||
return view;
|
||||
} else {
|
||||
return build(context);
|
||||
}
|
||||
}
|
||||
|
||||
return build(context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public View build(@NotNull Context context) {
|
||||
final View root = buildView(context);
|
||||
fillView(root, context);
|
||||
return root;
|
||||
}
|
||||
|
||||
private View buildView(@NotNull Context context) {
|
||||
return viewBuilder.build(context);
|
||||
}
|
||||
|
||||
private void fillView(@NotNull View root, @NotNull final Context context) {
|
||||
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());
|
||||
|
||||
final ImageButton settingsButton = (ImageButton) root.findViewById(R.id.cpp_plot_function_settings_button);
|
||||
settingsButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
CalculatorPlotFunctionSettingsActivity.startActivity(context, plotFunction);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@@ -1,14 +1,15 @@
|
||||
package org.solovyev.android.fragments;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.common.collections.CollectionsUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -18,10 +19,18 @@ import java.util.List;
|
||||
*/
|
||||
public class FragmentUtils {
|
||||
|
||||
public static void createFragment(@NotNull FragmentActivity activity,
|
||||
@NotNull Class<? extends Fragment> fragmentClass,
|
||||
int parentViewId,
|
||||
@NotNull String tag) {
|
||||
createFragment(activity, fragmentClass, parentViewId, tag, null);
|
||||
}
|
||||
|
||||
public static void createFragment(@NotNull FragmentActivity activity,
|
||||
@NotNull Class<? extends Fragment> fragmentClass,
|
||||
int parentViewId,
|
||||
@NotNull String tag) {
|
||||
@NotNull Class<? extends Fragment> fragmentClass,
|
||||
int parentViewId,
|
||||
@NotNull String tag,
|
||||
@Nullable Bundle args) {
|
||||
final FragmentManager fm = activity.getSupportFragmentManager();
|
||||
|
||||
Fragment messagesFragment = fm.findFragmentByTag(tag);
|
||||
@@ -29,7 +38,7 @@ public class FragmentUtils {
|
||||
final FragmentTransaction ft = fm.beginTransaction();
|
||||
try {
|
||||
if (messagesFragment == null) {
|
||||
messagesFragment = Fragment.instantiate(activity, fragmentClass.getName(), null);
|
||||
messagesFragment = Fragment.instantiate(activity, fragmentClass.getName(), args);
|
||||
ft.add(parentViewId, messagesFragment, tag);
|
||||
} else {
|
||||
if (messagesFragment.isDetached()) {
|
||||
|
Reference in New Issue
Block a user