new plotter
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user