new plotter
This commit is contained in:
parent
3f09528f45
commit
76719407db
BIN
android-app-core/res/drawable-hdpi/ab_list.png
Normal file
BIN
android-app-core/res/drawable-hdpi/ab_list.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
android-app-core/res/drawable-hdpi/ab_plot_2d.png
Normal file
BIN
android-app-core/res/drawable-hdpi/ab_plot_2d.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 891 B |
BIN
android-app-core/res/drawable-hdpi/ab_plot_3d.png
Normal file
BIN
android-app-core/res/drawable-hdpi/ab_plot_3d.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
android-app-core/res/drawable-xhdpi/ab_list.png
Normal file
BIN
android-app-core/res/drawable-xhdpi/ab_list.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 698 B |
BIN
android-app-core/res/drawable-xhdpi/ab_plot_2d.png
Normal file
BIN
android-app-core/res/drawable-xhdpi/ab_plot_2d.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
android-app-core/res/drawable-xhdpi/ab_plot_3d.png
Normal file
BIN
android-app-core/res/drawable-xhdpi/ab_plot_3d.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
26
android-app-core/res/layout/cpp_plot_function_list_item.xml
Normal file
26
android-app-core/res/layout/cpp_plot_function_list_item.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"
|
||||
a:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
a:id="@+id/cpp_plot_function_expression_textview"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_weight="5"/>
|
||||
|
||||
<CheckBox
|
||||
a:id="@+id/cpp_plot_function_pinned_checkbox"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_weight="1"/>
|
||||
|
||||
<CheckBox
|
||||
a:id="@+id/cpp_plot_function_visible_checkbox"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_weight="1"/>
|
||||
|
||||
</LinearLayout>
|
@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<TextView xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"/>
|
@ -282,7 +282,9 @@
|
||||
<string name="cpp_onscreen_remove_icon_message">You can remove second icon in applications\' list from application settings or by pressing next button</string>
|
||||
<string name="cpp_onscreen_remove_icon_button_text">Remove icon</string>
|
||||
<string name="cpp_this_change_may_require_reboot">This change may require reboot</string>
|
||||
<string name="cpp_plot_3d">3D</string>
|
||||
<string name="cpp_plot_2d">2D plot</string>
|
||||
<string name="cpp_plot_3d">3D plot</string>
|
||||
<string name="cpp_plot_functions">Graph functions</string>
|
||||
|
||||
<string name="cpp_prefs_graph_plot_imag_title">Plot imaginary part of function</string>
|
||||
<string name="cpp_prefs_graph_plot_imag_summary">If checked imaginary part of function will be plotted</string>
|
||||
|
@ -152,7 +152,30 @@
|
||||
|
||||
<item name="dropDownListViewStyle">@style/cpp_default_actionbar_dropdown_listview_style</item>
|
||||
<item name="android:dropDownListViewStyle">@style/cpp_default_actionbar_dropdown_listview_style</item>
|
||||
|
||||
|
||||
</style>
|
||||
|
||||
<style name="cpp_gray_dialog_theme" parent="Theme.Sherlock.Dialog">
|
||||
<!-- buttons -->
|
||||
<item name="cpp_digit_button_style">@style/cpp_default_digit_button_style</item>
|
||||
<item name="cpp_control_button_style">@style/cpp_default_control_button_style</item>
|
||||
<item name="cpp_control_image_button_style">@style/cpp_default_control_image_button_style</item>
|
||||
<item name="cpp_operation_button_style">@style/cpp_default_operation_button_style</item>
|
||||
|
||||
<!-- other -->
|
||||
<item name="cpp_fragment_title_style">@style/cpp_default_fragment_title_style</item>
|
||||
<item name="cpp_fragment_list_view_style">@style/cpp_default_fragment_list_view_style</item>
|
||||
<item name="cpp_fragment_list_view_item_style">@style/cpp_default_fragment_list_view_item_style</item>
|
||||
<item name="cpp_button_style">@style/cpp_default_button_style</item>
|
||||
|
||||
<item name="cpp_main_layout_style">@style/cpp_default_main_layout_style</item>
|
||||
<item name="cpp_main_multi_pane_layout_style">@style/cpp_default_main_multi_pane_layout_style</item>
|
||||
|
||||
<item name="cpp_fragment_layout_style">@style/cpp_default_fragment_layout_style</item>
|
||||
|
||||
<item name="cpp_dialog_style">@style/cpp_default_dialog_style</item>
|
||||
|
||||
<item name="cpp_pane_style">@style/cpp_default_pane_style</item>
|
||||
<item name="cpp_pane_style_transparent">@style/cpp_default_pane_style_transparent</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
@ -86,7 +86,7 @@ public enum CalculatorDisplayMenuItem implements LabeledMenuItem<CalculatorDispl
|
||||
|
||||
@Override
|
||||
protected boolean isItemVisibleFor(@NotNull Generic generic, @NotNull JsclOperation operation) {
|
||||
return Locator.getInstance().getPlotter().isPlotPossible(generic);
|
||||
return Locator.getInstance().getPlotter().isPlotPossibleFor(generic);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -77,24 +77,28 @@ public class AndroidCalculatorPlotter implements CalculatorPlotter, SharedPrefer
|
||||
return plotter.removeFunction(xyFunction);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public void pin(@NotNull PlotFunction plotFunction) {
|
||||
plotter.pin(plotFunction);
|
||||
public PlotFunction pin(@NotNull PlotFunction plotFunction) {
|
||||
return plotter.pin(plotFunction);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public void unpin(@NotNull PlotFunction plotFunction) {
|
||||
plotter.unpin(plotFunction);
|
||||
public PlotFunction unpin(@NotNull PlotFunction plotFunction) {
|
||||
return plotter.unpin(plotFunction);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public void show(@NotNull PlotFunction plotFunction) {
|
||||
plotter.show(plotFunction);
|
||||
public PlotFunction show(@NotNull PlotFunction plotFunction) {
|
||||
return plotter.show(plotFunction);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public void hide(@NotNull PlotFunction plotFunction) {
|
||||
plotter.hide(plotFunction);
|
||||
public PlotFunction hide(@NotNull PlotFunction plotFunction) {
|
||||
return plotter.hide(plotFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -120,8 +124,13 @@ public class AndroidCalculatorPlotter implements CalculatorPlotter, SharedPrefer
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlotPossible(@NotNull Generic expression) {
|
||||
return plotter.isPlotPossible(expression);
|
||||
public boolean is2dPlotPossible() {
|
||||
return plotter.is2dPlotPossible();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlotPossibleFor(@NotNull Generic expression) {
|
||||
return plotter.isPlotPossibleFor(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,57 +0,0 @@
|
||||
package org.solovyev.android.calculator.plot;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.core.R;
|
||||
import org.solovyev.android.list.ListItem;
|
||||
import org.solovyev.android.view.TextViewBuilder;
|
||||
import org.solovyev.android.view.UpdatableViewBuilder;
|
||||
|
||||
public class ParcelablePlotInputListItem implements ListItem {
|
||||
|
||||
@NotNull
|
||||
private XyFunction plotInput;
|
||||
|
||||
@NotNull
|
||||
private UpdatableViewBuilder<TextView> viewBuilder;
|
||||
|
||||
public ParcelablePlotInputListItem(@NotNull XyFunction plotInput) {
|
||||
this.plotInput = plotInput;
|
||||
// todo serso: use correct tag
|
||||
this.viewBuilder = TextViewBuilder.newInstance(R.layout.plot_functions_fragment_list_item, null);
|
||||
}
|
||||
|
||||
@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) {
|
||||
// todo serso: optimize
|
||||
return build(context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public View build(@NotNull Context context) {
|
||||
TextView textView = viewBuilder.build(context);
|
||||
fill(textView);
|
||||
return textView;
|
||||
}
|
||||
|
||||
private void fill(@NotNull TextView textView) {
|
||||
textView.setText(plotInput.getExpressionString());
|
||||
}
|
||||
}
|
@ -0,0 +1,119 @@
|
||||
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());
|
||||
}
|
||||
}
|
@ -52,6 +52,7 @@
|
||||
<activity android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsActivity"/>
|
||||
|
||||
<activity android:label="@string/c_plot_graph" android:name=".plot.CalculatorPlotActivity"/>
|
||||
<activity android:label="@string/c_plot_graph" android:name=".plot.CalculatorPlotFunctionsActivity" android:theme="@style/cpp_gray_dialog_theme"/>
|
||||
|
||||
<!-- todo serso: strings-->
|
||||
<activity android:label="@string/c_plot_graph" android:name=".matrix.CalculatorMatrixActivity"/>
|
||||
|
10
android-app/res/layout/cpp_plot_functions_dialog.xml
Normal file
10
android-app/res/layout/cpp_plot_functions_dialog.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:layout_width="wrap_content"
|
||||
a:layout_height="wrap_content"
|
||||
a:id="@+id/dialog_layout"
|
||||
style="?cpp_dialog_style"
|
||||
a:orientation="vertical">
|
||||
|
||||
</LinearLayout>
|
@ -1,18 +1,45 @@
|
||||
<?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="match_parent"
|
||||
a:layout_height="match_parent">
|
||||
a:id="@+id/main_fragment_layout"
|
||||
style="?cpp_fragment_layout_style"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="match_parent">
|
||||
|
||||
<TextView a:id="@+id/fragment_title"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="match_parent"
|
||||
style="?cpp_fragment_title_style"/>
|
||||
<TextView
|
||||
a:id="@+id/fragment_title"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="match_parent"
|
||||
style="?cpp_fragment_title_style" />
|
||||
|
||||
<include layout="@layout/ad"/>
|
||||
<include layout="@layout/ad" />
|
||||
|
||||
<ListView style="?cpp_fragment_list_view_style"/>
|
||||
<LinearLayout
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"
|
||||
a:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_weight="5"
|
||||
a:text="Function"/>
|
||||
|
||||
<TextView
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_weight="1"
|
||||
a:text="Pinned"/>
|
||||
|
||||
<TextView
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_weight="1"
|
||||
a:text="Visible"/>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ListView style="?cpp_fragment_list_view_style" />
|
||||
|
||||
</LinearLayout>
|
@ -8,9 +8,19 @@
|
||||
|
||||
<menu xmlns:a="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item a:id="@+id/menu_plot_2d"
|
||||
a:title="@string/cpp_plot_2d"
|
||||
a:icon="@drawable/ab_plot_2d"
|
||||
a:showAsAction="always"/>
|
||||
|
||||
<item a:id="@+id/menu_plot_3d"
|
||||
a:title="@string/cpp_plot_3d"
|
||||
a:icon="@drawable/ab_icon"
|
||||
a:icon="@drawable/ab_plot_3d"
|
||||
a:showAsAction="always"/>
|
||||
|
||||
<item a:id="@+id/menu_plot_functions"
|
||||
a:title="@string/cpp_plot_functions"
|
||||
a:icon="@drawable/ab_list"
|
||||
a:showAsAction="always"/>
|
||||
|
||||
<item a:id="@+id/menu_plot_settings"
|
||||
|
@ -14,10 +14,12 @@ import org.achartengine.renderer.XYMultipleSeriesRenderer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.menu.AMenuItem;
|
||||
import org.solovyev.android.menu.ActivityMenu;
|
||||
import org.solovyev.android.menu.IdentifiableMenuItem;
|
||||
import org.solovyev.android.menu.ListActivityMenu;
|
||||
import org.solovyev.android.sherlock.menu.SherlockMenuHelper;
|
||||
import org.solovyev.common.JPredicate;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
@ -97,13 +99,6 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
this.plotData = Locator.getInstance().getPlotter().getPlotData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle out) {
|
||||
super.onSaveInstanceState(out);
|
||||
@ -121,8 +116,10 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
plotData = Locator.getInstance().getPlotter().getPlotData();
|
||||
createChart(plotData);
|
||||
createGraphicalView(getView(), plotData);
|
||||
getActivity().invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -141,6 +138,8 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
|
||||
getUiHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getActivity().invalidateOptionsMenu();
|
||||
|
||||
createChart(plotData);
|
||||
|
||||
final View view = getView();
|
||||
@ -197,26 +196,55 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
public void onCreateOptionsMenu(final Menu menu, MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
|
||||
final List<IdentifiableMenuItem<MenuItem>> menuItems = new ArrayList<IdentifiableMenuItem<MenuItem>>();
|
||||
menuItems.add(PlotMenu.preferences);
|
||||
if ( is3dPlotSupported() ) {
|
||||
menuItems.add(new IdentifiableMenuItem<MenuItem>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Integer getItemId() {
|
||||
return R.id.menu_plot_3d;
|
||||
}
|
||||
menuItems.add(PlotMenu.functions);
|
||||
|
||||
@Override
|
||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||
Locator.getInstance().getPlotter().setPlot3d(true);
|
||||
final IdentifiableMenuItem<MenuItem> plot3dMenuItem = new IdentifiableMenuItem<MenuItem>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Integer getItemId() {
|
||||
return R.id.menu_plot_3d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||
Locator.getInstance().getPlotter().setPlot3d(true);
|
||||
}
|
||||
};
|
||||
menuItems.add(plot3dMenuItem);
|
||||
|
||||
|
||||
final IdentifiableMenuItem<MenuItem> plot2dMenuItem = new IdentifiableMenuItem<MenuItem>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Integer getItemId() {
|
||||
return R.id.menu_plot_2d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||
Locator.getInstance().getPlotter().setPlot3d(false);
|
||||
}
|
||||
};
|
||||
menuItems.add(plot2dMenuItem);
|
||||
|
||||
final boolean plot3dVisible = !plotData.isPlot3d() && is3dPlotSupported();
|
||||
final boolean plot2dVisible = plotData.isPlot3d() && Locator.getInstance().getPlotter().is2dPlotPossible();
|
||||
fragmentMenu = ListActivityMenu.fromResource(R.menu.plot_menu, menuItems, SherlockMenuHelper.getInstance(), new JPredicate<AMenuItem<MenuItem>>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable AMenuItem<MenuItem> menuItem) {
|
||||
if ( menuItem == plot3dMenuItem ) {
|
||||
return !plot3dVisible;
|
||||
} else if ( menuItem == plot2dMenuItem ) {
|
||||
return !plot2dVisible;
|
||||
}
|
||||
});
|
||||
}
|
||||
fragmentMenu = ListActivityMenu.fromResource(R.menu.plot_menu, menuItems, SherlockMenuHelper.getInstance());
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
final FragmentActivity activity = this.getActivity();
|
||||
if (activity != null) {
|
||||
@ -251,6 +279,13 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
|
||||
|
||||
private static enum PlotMenu implements IdentifiableMenuItem<MenuItem> {
|
||||
|
||||
functions(R.id.menu_plot_functions) {
|
||||
@Override
|
||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||
context.startActivity(new Intent(context, CalculatorPlotFunctionsActivity.class));
|
||||
}
|
||||
},
|
||||
|
||||
preferences(R.id.menu_plot_settings) {
|
||||
@Override
|
||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||
|
@ -0,0 +1,24 @@
|
||||
package org.solovyev.android.calculator.plot;
|
||||
|
||||
import android.os.Bundle;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.fragments.FragmentUtils;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 1/13/13
|
||||
* Time: 5:05 PM
|
||||
*/
|
||||
public class CalculatorPlotFunctionsActivity extends SherlockFragmentActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.cpp_plot_functions_dialog);
|
||||
|
||||
FragmentUtils.createFragment(this, CalculatorPlotFunctionsFragment.class, R.id.dialog_layout, "plot-functions");
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package org.solovyev.android.calculator.plot;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
final class CalculatorPlotFunctionsController {
|
||||
|
||||
@NotNull
|
||||
private static final CalculatorPlotFunctionsController instance = new CalculatorPlotFunctionsController();
|
||||
|
||||
@NotNull
|
||||
private final List<XyFunction> functions = new ArrayList<XyFunction>();
|
||||
|
||||
private CalculatorPlotFunctionsController() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static CalculatorPlotFunctionsController getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<XyFunction> getFunctions() {
|
||||
return Collections.unmodifiableList(functions);
|
||||
}
|
||||
|
||||
public boolean addFunction(@NotNull XyFunction function) {
|
||||
if (!functions.contains(function)) {
|
||||
return functions.add(function);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ 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;
|
||||
|
||||
@ -23,10 +24,11 @@ public class CalculatorPlotFunctionsFragment extends CalculatorListFragment {
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
final List<ParcelablePlotInputListItem> items = Lists.transform(CalculatorPlotFunctionsController.getInstance().getFunctions(), new Function<XyFunction, ParcelablePlotInputListItem>() {
|
||||
final List<PlotFunctionListItem> items = Lists.transform(Locator.getInstance().getPlotter().getFunctions(), new Function<PlotFunction, PlotFunctionListItem>() {
|
||||
@Override
|
||||
public ParcelablePlotInputListItem apply(@Nullable XyFunction input) {
|
||||
return new ParcelablePlotInputListItem(input);
|
||||
public PlotFunctionListItem apply(@Nullable PlotFunction input) {
|
||||
assert input != null;
|
||||
return new PlotFunctionListItem(input);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -26,11 +26,17 @@ public interface CalculatorPlotter {
|
||||
boolean removeFunction(@NotNull PlotFunction plotFunction);
|
||||
boolean removeFunction(@NotNull XyFunction xyFunction);
|
||||
|
||||
void pin(@NotNull PlotFunction plotFunction);
|
||||
void unpin(@NotNull PlotFunction plotFunction);
|
||||
@NotNull
|
||||
PlotFunction pin(@NotNull PlotFunction plotFunction);
|
||||
|
||||
void show(@NotNull PlotFunction plotFunction);
|
||||
void hide(@NotNull PlotFunction plotFunction);
|
||||
@NotNull
|
||||
PlotFunction unpin(@NotNull PlotFunction plotFunction);
|
||||
|
||||
@NotNull
|
||||
PlotFunction show(@NotNull PlotFunction plotFunction);
|
||||
|
||||
@NotNull
|
||||
PlotFunction hide(@NotNull PlotFunction plotFunction);
|
||||
|
||||
void clearAllFunctions();
|
||||
|
||||
@ -42,7 +48,9 @@ public interface CalculatorPlotter {
|
||||
|
||||
void plot();
|
||||
|
||||
boolean isPlotPossible(@NotNull Generic expression);
|
||||
boolean is2dPlotPossible();
|
||||
|
||||
boolean isPlotPossibleFor(@NotNull Generic expression);
|
||||
|
||||
void setPlot3d(boolean plot3d);
|
||||
|
||||
|
@ -31,6 +31,8 @@ public class CalculatorPlotterImpl implements CalculatorPlotter {
|
||||
|
||||
private boolean plotImag = false;
|
||||
|
||||
private int arity = 0;
|
||||
|
||||
@NotNull
|
||||
private GraphLineColor realLineColor;
|
||||
|
||||
@ -134,6 +136,14 @@ public class CalculatorPlotterImpl implements CalculatorPlotter {
|
||||
|
||||
@Override
|
||||
public boolean updateFunction(@NotNull PlotFunction newFunction) {
|
||||
boolean changed = updateFunction0(newFunction);
|
||||
if (changed) {
|
||||
firePlotDataChangedEvent();
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
public boolean updateFunction0(@NotNull PlotFunction newFunction) {
|
||||
boolean changed = false;
|
||||
|
||||
synchronized (functions) {
|
||||
@ -156,26 +166,40 @@ public class CalculatorPlotterImpl implements CalculatorPlotter {
|
||||
return removeFunction(new PlotFunction(xyFunction));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public void pin(@NotNull PlotFunction plotFunction) {
|
||||
updateFunction(PlotFunction.pin(plotFunction));
|
||||
public PlotFunction pin(@NotNull PlotFunction plotFunction) {
|
||||
final PlotFunction newFunction = PlotFunction.pin(plotFunction);
|
||||
updateFunction0(newFunction);
|
||||
return newFunction;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public void unpin(@NotNull PlotFunction plotFunction) {
|
||||
updateFunction(PlotFunction.unpin(plotFunction));
|
||||
public PlotFunction unpin(@NotNull PlotFunction plotFunction) {
|
||||
final PlotFunction newFunction = PlotFunction.unpin(plotFunction);
|
||||
updateFunction0(newFunction);
|
||||
return newFunction;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public void show(@NotNull PlotFunction plotFunction) {
|
||||
updateFunction(PlotFunction.visible(plotFunction));
|
||||
firePlotDataChangedEvent();
|
||||
public PlotFunction show(@NotNull PlotFunction plotFunction) {
|
||||
final PlotFunction newFunction = PlotFunction.visible(plotFunction);
|
||||
|
||||
updateFunction(newFunction);
|
||||
|
||||
return newFunction;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public void hide(@NotNull PlotFunction plotFunction) {
|
||||
updateFunction(PlotFunction.invisible(plotFunction));
|
||||
firePlotDataChangedEvent();
|
||||
public PlotFunction hide(@NotNull PlotFunction plotFunction) {
|
||||
final PlotFunction newFunction = PlotFunction.invisible(plotFunction);
|
||||
|
||||
updateFunction(newFunction);
|
||||
|
||||
return newFunction;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -203,6 +227,8 @@ public class CalculatorPlotterImpl implements CalculatorPlotter {
|
||||
plot3d = false;
|
||||
}
|
||||
|
||||
arity = maxArity;
|
||||
|
||||
firePlotDataChangedEvent();
|
||||
}
|
||||
|
||||
@ -233,7 +259,12 @@ public class CalculatorPlotterImpl implements CalculatorPlotter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlotPossible(@NotNull Generic expression) {
|
||||
public boolean is2dPlotPossible() {
|
||||
return arity < 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlotPossibleFor(@NotNull Generic expression) {
|
||||
boolean result = false;
|
||||
|
||||
int size = CalculatorUtils.getNotSystemConstants(expression).size();
|
||||
|
@ -42,27 +42,36 @@ public class PlotFunction {
|
||||
}
|
||||
|
||||
public static PlotFunction pin(@NotNull PlotFunction that) {
|
||||
return togglePinned(that, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PlotFunction togglePinned(@NotNull PlotFunction that, boolean pinned) {
|
||||
final PlotFunction copy = that.copy();
|
||||
copy.pinned = true;
|
||||
copy.pinned = pinned;
|
||||
return copy;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PlotFunction unpin(@NotNull PlotFunction that) {
|
||||
final PlotFunction copy = that.copy();
|
||||
copy.pinned = false;
|
||||
return copy;
|
||||
return togglePinned(that, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PlotFunction visible(@NotNull PlotFunction that) {
|
||||
return toggleVisible(that, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PlotFunction toggleVisible(@NotNull PlotFunction that, boolean visible) {
|
||||
final PlotFunction copy = that.copy();
|
||||
copy.visible = true;
|
||||
copy.visible = visible;
|
||||
return copy;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PlotFunction invisible(@NotNull PlotFunction that) {
|
||||
final PlotFunction copy = that.copy();
|
||||
copy.visible = false;
|
||||
return copy;
|
||||
return toggleVisible(that, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
Loading…
Reference in New Issue
Block a user