new plotter
This commit is contained in:
parent
220952ef9b
commit
8d2a0458e2
@ -317,6 +317,8 @@
|
|||||||
<string name="cpp_plot_range_x_min">X Min</string>
|
<string name="cpp_plot_range_x_min">X Min</string>
|
||||||
<string name="cpp_plot_range_x_max">X Max</string>
|
<string name="cpp_plot_range_x_max">X Max</string>
|
||||||
<string name="cpp_invalid_number">Invalid number!</string>
|
<string name="cpp_invalid_number">Invalid number!</string>
|
||||||
|
<string name="cpp_plot_boundaries_should_differ">Graph boundaries should not be the same!</string>
|
||||||
|
<string name="cpp_apply">Apply</string>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -55,6 +55,7 @@
|
|||||||
<activity android:label="@string/c_plot_graph" android:name=".plot.CalculatorPlotActivity"/>
|
<activity android:label="@string/c_plot_graph" android:name=".plot.CalculatorPlotActivity"/>
|
||||||
<activity android:launchMode="singleTop" android:label="@string/cpp_plot_functions" android:name=".plot.CalculatorPlotFunctionsActivity" android:theme="@style/cpp_gray_dialog_theme"/>
|
<activity android:launchMode="singleTop" android:label="@string/cpp_plot_functions" android:name=".plot.CalculatorPlotFunctionsActivity" android:theme="@style/cpp_gray_dialog_theme"/>
|
||||||
<activity android:launchMode="singleTop" android:label="@string/cpp_plot_function_settings" android:name=".plot.CalculatorPlotFunctionSettingsActivity" android:theme="@style/cpp_gray_dialog_theme"/>
|
<activity android:launchMode="singleTop" android:label="@string/cpp_plot_function_settings" android:name=".plot.CalculatorPlotFunctionSettingsActivity" android:theme="@style/cpp_gray_dialog_theme"/>
|
||||||
|
<activity android:launchMode="singleTop" android:label="@string/cpp_plot_range" android:name=".plot.CalculatorPlotRangeActivity" android:theme="@style/cpp_gray_dialog_theme"/>
|
||||||
|
|
||||||
<!-- todo serso: strings-->
|
<!-- todo serso: strings-->
|
||||||
<activity android:label="@string/c_plot_graph" android:name=".matrix.CalculatorMatrixActivity"/>
|
<activity android:label="@string/c_plot_graph" android:name=".matrix.CalculatorMatrixActivity"/>
|
||||||
|
@ -45,8 +45,8 @@
|
|||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="wrap_content"/>
|
a:layout_height="wrap_content"/>
|
||||||
|
|
||||||
<Button a:id="@+id/cpp_ok_button"
|
<Button a:id="@+id/cpp_apply_button"
|
||||||
a:text="@string/ok"
|
a:text="@string/cpp_apply"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="wrap_content"/>
|
a:layout_height="wrap_content"/>
|
||||||
|
|
||||||
|
@ -3,35 +3,62 @@
|
|||||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/main_fragment_layout"
|
a:id="@+id/main_fragment_layout"
|
||||||
style="?cpp_fragment_layout_style"
|
style="?cpp_fragment_layout_style"
|
||||||
a:layout_width="wrap_content"
|
a:layout_width="match_parent"
|
||||||
a:layout_gravity="center_horizontal"
|
a:layout_gravity="center_horizontal"
|
||||||
a:layout_height="match_parent"
|
a:layout_height="match_parent"
|
||||||
a:orientation="vertical">
|
a:orientation="vertical">
|
||||||
|
|
||||||
<include layout="@layout/ad" />
|
<include layout="@layout/ad" />
|
||||||
|
|
||||||
<TextView a:text="@string/cpp_plot_range_x_min"
|
<LinearLayout
|
||||||
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_width="match_parent"
|
||||||
a:layout_height="wrap_content"/>
|
a:layout_height="wrap_content"
|
||||||
|
a:orientation="horizontal"
|
||||||
|
a:baselineAligned="false">
|
||||||
|
|
||||||
<EditText a:id="@+id/cpp_plot_range_x_max_editext"
|
<LinearLayout
|
||||||
a:inputType="numberDecimal"
|
a:layout_width="0dp"
|
||||||
|
a:layout_height="wrap_content"
|
||||||
|
a:layout_weight="1"
|
||||||
|
a:orientation="vertical">
|
||||||
|
|
||||||
|
<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|numberSigned"
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="wrap_content" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
a:layout_width="0dp"
|
||||||
|
a:layout_height="wrap_content"
|
||||||
|
a:layout_weight="1"
|
||||||
|
a:orientation="vertical">
|
||||||
|
|
||||||
|
<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|numberSigned"
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="wrap_content" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
a:id="@+id/cpp_apply_button"
|
||||||
|
a:text="@string/cpp_apply"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="wrap_content"/>
|
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>
|
</LinearLayout>
|
@ -18,6 +18,11 @@
|
|||||||
a:icon="@drawable/ab_plot_3d"
|
a:icon="@drawable/ab_plot_3d"
|
||||||
a:showAsAction="always"/>
|
a:showAsAction="always"/>
|
||||||
|
|
||||||
|
<item a:id="@+id/menu_plot_range"
|
||||||
|
a:title="@string/cpp_plot_range"
|
||||||
|
a:icon="@drawable/ab_plot_range"
|
||||||
|
a:showAsAction="always"/>
|
||||||
|
|
||||||
<item a:id="@+id/menu_plot_functions"
|
<item a:id="@+id/menu_plot_functions"
|
||||||
a:title="@string/cpp_plot_functions"
|
a:title="@string/cpp_plot_functions"
|
||||||
a:icon="@drawable/ab_list"
|
a:icon="@drawable/ab_list"
|
||||||
|
@ -184,6 +184,7 @@ 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);
|
||||||
|
|
||||||
@ -307,6 +308,13 @@ 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) {
|
||||||
|
@ -4,12 +4,9 @@ import android.app.Activity;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Message;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
@ -24,208 +21,152 @@ import org.solovyev.android.fragments.FragmentUtils;
|
|||||||
|
|
||||||
public class CalculatorPlotFunctionSettingsActivity extends SherlockFragmentActivity {
|
public class CalculatorPlotFunctionSettingsActivity extends SherlockFragmentActivity {
|
||||||
|
|
||||||
private static final String INPUT_FUNCTION_ID = "plot-function-id";
|
private static final String INPUT_FUNCTION_ID = "plot-function-id";
|
||||||
|
|
||||||
public static void startActivity(@NotNull Context context, @NotNull PlotFunction plotFunction) {
|
public static void startActivity(@NotNull Context context, @NotNull PlotFunction plotFunction) {
|
||||||
final Intent intent = new Intent(context, CalculatorPlotFunctionSettingsActivity.class);
|
final Intent intent = new Intent(context, CalculatorPlotFunctionSettingsActivity.class);
|
||||||
intent.putExtra(INPUT_FUNCTION_ID, plotFunction.getXyFunction().getId());
|
intent.putExtra(INPUT_FUNCTION_ID, plotFunction.getXyFunction().getId());
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
setContentView(R.layout.cpp_plot_function_settings_dialog);
|
setContentView(R.layout.cpp_plot_function_settings_dialog);
|
||||||
|
|
||||||
final Intent intent = getIntent();
|
final Intent intent = getIntent();
|
||||||
|
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
final String plotFunctionId = intent.getStringExtra(INPUT_FUNCTION_ID);
|
final String plotFunctionId = intent.getStringExtra(INPUT_FUNCTION_ID);
|
||||||
|
|
||||||
if (plotFunctionId != null) {
|
if (plotFunctionId != null) {
|
||||||
final Bundle parameters = new Bundle();
|
final Bundle parameters = new Bundle();
|
||||||
parameters.putString(INPUT_FUNCTION_ID, plotFunctionId);
|
parameters.putString(INPUT_FUNCTION_ID, plotFunctionId);
|
||||||
FragmentUtils.createFragment(this, CalculatorPlotFunctionSettingsFragment.class, R.id.dialog_layout, "plot-function-settings", parameters);
|
FragmentUtils.createFragment(this, CalculatorPlotFunctionSettingsFragment.class, R.id.dialog_layout, "plot-function-settings", parameters);
|
||||||
} else {
|
} else {
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CalculatorPlotFunctionSettingsFragment extends CalculatorFragment {
|
public static class CalculatorPlotFunctionSettingsFragment extends CalculatorFragment {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*
|
*
|
||||||
* STATIC
|
* STATIC
|
||||||
*
|
*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static final int LINE_WIDTH_DELAY = 1000;
|
@Nullable
|
||||||
public static final int MESSAGE_ID = 1;
|
private PlotFunction plotFunction;
|
||||||
|
|
||||||
@Nullable
|
@NotNull
|
||||||
private PlotFunction plotFunction;
|
private final CalculatorPlotter plotter = Locator.getInstance().getPlotter();
|
||||||
|
|
||||||
@NotNull
|
public CalculatorPlotFunctionSettingsFragment() {
|
||||||
private final CalculatorPlotter plotter = Locator.getInstance().getPlotter();
|
super(CalculatorFragmentType.plotter_function_settings);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@Override
|
||||||
private final Handler handler = new Handler() {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
@Override
|
final String functionId = getArguments().getString(INPUT_FUNCTION_ID);
|
||||||
public void handleMessage(Message msg) {
|
if (functionId != null) {
|
||||||
if (plotFunction != null) {
|
plotFunction = Locator.getInstance().getPlotter().getFunctionById(functionId);
|
||||||
switch (msg.what) {
|
if (plotFunction != null) {
|
||||||
case MESSAGE_ID:
|
getActivity().setTitle(plotFunction.getXyFunction().getExpressionString());
|
||||||
final PlotLineDef newPlotLineDef = PlotLineDef.changeLineWidth(plotFunction.getPlotLineDef(), msg.arg1);
|
}
|
||||||
final PlotFunction newPlotFunction = PlotFunction.changePlotLineDef(plotFunction, newPlotLineDef);
|
}
|
||||||
if(plotter.updateFunction(newPlotFunction)) {
|
}
|
||||||
plotFunction = newPlotFunction;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public CalculatorPlotFunctionSettingsFragment() {
|
@Override
|
||||||
super(CalculatorFragmentType.plotter_function_settings);
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
}
|
return super.onCreateView(inflater, container, savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onViewCreated(root, savedInstanceState);
|
||||||
|
|
||||||
final String functionId = getArguments().getString(INPUT_FUNCTION_ID);
|
final Spinner plotLineColorSpinner = (Spinner) root.findViewById(R.id.cpp_plot_function_line_color_spinner);
|
||||||
if (functionId != null) {
|
final Spinner plotLineColorTypeSpinner = (Spinner) root.findViewById(R.id.cpp_plot_function_line_color_type_spinner);
|
||||||
plotFunction = Locator.getInstance().getPlotter().getFunctionById(functionId);
|
final Spinner plotLineStyleSpinner = (Spinner) root.findViewById(R.id.cpp_plot_function_line_style_spinner);
|
||||||
if ( plotFunction != null ) {
|
final SeekBar plotLineWidthSeekBar = (SeekBar) root.findViewById(R.id.cpp_plot_functions_line_width_seekbar);
|
||||||
getActivity().setTitle(plotFunction.getXyFunction().getExpressionString());
|
final Button okButton = (Button) root.findViewById(R.id.cpp_apply_button);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
plotLineWidthSeekBar.setMax(10);
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
||||||
return super.onCreateView(inflater, container, savedInstanceState);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (plotFunction != null) {
|
||||||
public void onViewCreated(View root, Bundle savedInstanceState) {
|
plotLineWidthSeekBar.setProgress((int) plotFunction.getPlotLineDef().getLineWidth());
|
||||||
super.onViewCreated(root, savedInstanceState);
|
plotLineColorSpinner.setSelection(PlotLineColor.valueOf(plotFunction.getPlotLineDef().getLineColor()).ordinal());
|
||||||
|
plotLineColorTypeSpinner.setSelection(plotFunction.getPlotLineDef().getLineColorType().ordinal());
|
||||||
|
plotLineStyleSpinner.setSelection(plotFunction.getPlotLineDef().getLineStyle().ordinal());
|
||||||
|
|
||||||
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 SeekBar plotLineWidthSeekBar = (SeekBar)root.findViewById(R.id.cpp_plot_functions_line_width_seekbar);
|
|
||||||
final Button okButton = (Button)root.findViewById(R.id.cpp_ok_button);
|
|
||||||
|
|
||||||
plotLineWidthSeekBar.setMax(10);
|
okButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
|
||||||
if (plotFunction != null) {
|
PlotFunction plotFunction = CalculatorPlotFunctionSettingsFragment.this.plotFunction;
|
||||||
plotLineWidthSeekBar.setProgress((int)plotFunction.getPlotLineDef().getLineWidth());
|
|
||||||
|
|
||||||
plotLineColorSpinner.setSelection(PlotLineColor.valueOf(plotFunction.getPlotLineDef().getLineColor()).ordinal());
|
// color
|
||||||
plotLineColorSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
final PlotLineColor newPlotLineColor = PlotLineColor.values()[plotLineColorSpinner.getSelectedItemPosition()];
|
||||||
@Override
|
int newLineColor = newPlotLineColor.getColor();
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
if (newLineColor != plotFunction.getPlotLineDef().getLineColor()) {
|
||||||
final PlotLineColor newPlotLineColor = PlotLineColor.values()[position];
|
final PlotLineDef newPlotLineDef = PlotLineDef.changeLineColor(plotFunction.getPlotLineDef(), newLineColor);
|
||||||
int newLineColor = newPlotLineColor.getColor();
|
plotFunction = PlotFunction.changePlotLineDef(plotFunction, newPlotLineDef);
|
||||||
if ( newLineColor != plotFunction.getPlotLineDef().getLineColor() ) {
|
}
|
||||||
final PlotLineDef newPlotLineDef = PlotLineDef.changeLineColor(plotFunction.getPlotLineDef(), newLineColor);
|
|
||||||
final PlotFunction newPlotFunction = PlotFunction.changePlotLineDef(plotFunction, newPlotLineDef);
|
|
||||||
if(plotter.updateFunction(newPlotFunction)) {
|
|
||||||
plotFunction = newPlotFunction;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
// color type
|
||||||
public void onNothingSelected(AdapterView<?> parent) {
|
final PlotLineColorType newPlotLineColorType = PlotLineColorType.values()[plotLineColorTypeSpinner.getSelectedItemPosition()];
|
||||||
}
|
if (newPlotLineColorType != CalculatorPlotFunctionSettingsFragment.this.plotFunction.getPlotLineDef().getLineColorType()) {
|
||||||
});
|
final PlotLineDef newPlotLineDef = PlotLineDef.changeLineColorType(plotFunction.getPlotLineDef(), newPlotLineColorType);
|
||||||
|
plotFunction = PlotFunction.changePlotLineDef(plotFunction, newPlotLineDef);
|
||||||
|
}
|
||||||
|
|
||||||
plotLineColorTypeSpinner.setSelection(plotFunction.getPlotLineDef().getLineColorType().ordinal());
|
// line style
|
||||||
plotLineColorTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
final PlotLineStyle newPlotLineStyle = PlotLineStyle.values()[plotLineStyleSpinner.getSelectedItemPosition()];
|
||||||
@Override
|
if (newPlotLineStyle != plotFunction.getPlotLineDef().getLineStyle()) {
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
final PlotLineDef newPlotLineDef = PlotLineDef.changeLineStyle(plotFunction.getPlotLineDef(), newPlotLineStyle);
|
||||||
final PlotLineColorType newPlotLineColorType = PlotLineColorType.values()[position];
|
plotFunction = PlotFunction.changePlotLineDef(plotFunction, newPlotLineDef);
|
||||||
if ( newPlotLineColorType != plotFunction.getPlotLineDef().getLineColorType() ) {
|
}
|
||||||
final PlotLineDef newPlotLineDef = PlotLineDef.changeLineColorType(plotFunction.getPlotLineDef(), newPlotLineColorType);
|
|
||||||
final PlotFunction newPlotFunction = PlotFunction.changePlotLineDef(plotFunction, newPlotLineDef);
|
|
||||||
if(plotter.updateFunction(newPlotFunction)) {
|
|
||||||
plotFunction = newPlotFunction;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
// width
|
||||||
public void onNothingSelected(AdapterView<?> parent) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
plotLineStyleSpinner.setSelection(plotFunction.getPlotLineDef().getLineStyle().ordinal());
|
final int newPlotLineWidth = plotLineWidthSeekBar.getProgress();
|
||||||
plotLineStyleSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
if (((float) newPlotLineWidth) != plotFunction.getPlotLineDef().getLineWidth()) {
|
||||||
@Override
|
final PlotLineDef newPlotLineDef = PlotLineDef.changeLineWidth(plotFunction.getPlotLineDef(), newPlotLineWidth);
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
plotFunction = PlotFunction.changePlotLineDef(plotFunction, newPlotLineDef);
|
||||||
final PlotLineStyle newPlotLineStyle = PlotLineStyle.values()[position];
|
}
|
||||||
if ( newPlotLineStyle != plotFunction.getPlotLineDef().getLineStyle() ) {
|
|
||||||
|
|
||||||
final PlotLineDef newPlotLineDef = PlotLineDef.changeLineStyle(plotFunction.getPlotLineDef(), newPlotLineStyle);
|
if (plotFunction != CalculatorPlotFunctionSettingsFragment.this.plotFunction) {
|
||||||
final PlotFunction newPlotFunction = PlotFunction.changePlotLineDef(plotFunction, newPlotLineDef);
|
// if has been changed
|
||||||
|
|
||||||
if(plotter.updateFunction(newPlotFunction)) {
|
if (plotter.updateFunction(plotFunction)) {
|
||||||
plotFunction = newPlotFunction;
|
CalculatorPlotFunctionSettingsFragment.this.plotFunction = plotFunction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
final Activity activity = getActivity();
|
||||||
public void onNothingSelected(AdapterView<?> parent) {
|
if (activity != null) {
|
||||||
}
|
activity.finish();
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
plotLineWidthSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
} else {
|
||||||
@Override
|
plotLineWidthSeekBar.setEnabled(false);
|
||||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
plotLineColorSpinner.setEnabled(false);
|
||||||
// remove old messages
|
plotLineColorTypeSpinner.setEnabled(false);
|
||||||
handler.removeMessages(MESSAGE_ID);
|
plotLineStyleSpinner.setEnabled(false);
|
||||||
|
okButton.setEnabled(false);
|
||||||
// send new message
|
}
|
||||||
handler.sendMessageDelayed(Message.obtain(handler, MESSAGE_ID, progress, 0), LINE_WIDTH_DELAY);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
okButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
final Activity activity = getActivity();
|
|
||||||
if ( activity != null ) {
|
|
||||||
activity.finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
|
||||||
plotLineWidthSeekBar.setEnabled(false);
|
|
||||||
plotLineColorSpinner.setEnabled(false);
|
|
||||||
plotLineColorTypeSpinner.setEnabled(false);
|
|
||||||
plotLineStyleSpinner.setEnabled(false);
|
|
||||||
okButton.setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
package org.solovyev.android.calculator.plot;
|
package org.solovyev.android.calculator.plot;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.Editable;
|
|
||||||
import android.text.TextWatcher;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.solovyev.android.calculator.CalculatorFragment;
|
||||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||||
import org.solovyev.android.calculator.CalculatorListFragment;
|
|
||||||
import org.solovyev.android.calculator.Locator;
|
import org.solovyev.android.calculator.Locator;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
import org.solovyev.android.fragments.FragmentUtils;
|
import org.solovyev.android.fragments.FragmentUtils;
|
||||||
@ -31,7 +29,7 @@ public class CalculatorPlotRangeActivity extends SherlockFragmentActivity {
|
|||||||
FragmentUtils.createFragment(this, CalculatorPlotRangeFragment.class, R.id.dialog_layout, "plot-range");
|
FragmentUtils.createFragment(this, CalculatorPlotRangeFragment.class, R.id.dialog_layout, "plot-range");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CalculatorPlotRangeFragment extends CalculatorListFragment {
|
public static class CalculatorPlotRangeFragment extends CalculatorFragment {
|
||||||
|
|
||||||
public CalculatorPlotRangeFragment() {
|
public CalculatorPlotRangeFragment() {
|
||||||
super(CalculatorFragmentType.plotter_range);
|
super(CalculatorFragmentType.plotter_range);
|
||||||
@ -52,53 +50,29 @@ public class CalculatorPlotRangeActivity extends SherlockFragmentActivity {
|
|||||||
xMinEditText.setText(String.valueOf(boundaries.getXMin()));
|
xMinEditText.setText(String.valueOf(boundaries.getXMin()));
|
||||||
xMaxEditText.setText(String.valueOf(boundaries.getXMax()));
|
xMaxEditText.setText(String.valueOf(boundaries.getXMax()));
|
||||||
|
|
||||||
xMinEditText.addTextChangedListener(new TextWatcher() {
|
root.findViewById(R.id.cpp_apply_button).setOnClickListener(new View.OnClickListener() {
|
||||||
@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
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
CalculatorPlotRangeFragment.this.getActivity().finish();
|
|
||||||
|
try {
|
||||||
|
final Float xMin = Float.valueOf(xMinEditText.getText().toString());
|
||||||
|
final Float xMax = Float.valueOf(xMaxEditText.getText().toString());
|
||||||
|
|
||||||
|
if ( xMin.equals(xMax) ) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
|
plotter.setPlotBoundaries(PlotBoundaries.newInstance(xMin, xMax));
|
||||||
|
|
||||||
|
CalculatorPlotRangeFragment.this.getActivity().finish();
|
||||||
|
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
if (e instanceof NumberFormatException) {
|
||||||
|
Locator.getInstance().getNotifier().showMessage(R.string.cpp_invalid_number, MessageType.error);
|
||||||
|
} else {
|
||||||
|
Locator.getInstance().getNotifier().showMessage(R.string.cpp_plot_boundaries_should_differ, MessageType.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,10 @@ public final class PlotBoundaries implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PlotBoundaries(float xMin, float xMax, float yMin, float yMax) {
|
PlotBoundaries(float xMin, float xMax, float yMin, float yMax) {
|
||||||
this.xMin = xMin;
|
this.xMin = Math.min(xMin, xMax);
|
||||||
this.xMax = xMax;
|
this.xMax = Math.max(xMin, xMax);
|
||||||
this.yMin = yMin;
|
this.yMin = Math.min(yMin, yMax);
|
||||||
this.yMax = yMax;
|
this.yMax = Math.max(yMin, yMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
Loading…
Reference in New Issue
Block a user