Plotter preferences

This commit is contained in:
Sergey Solovyev 2012-10-05 01:14:18 +04:00
parent d84e5437b4
commit c1a65f4aad
21 changed files with 139 additions and 103 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -3,4 +3,4 @@
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/ad_parent_view" a:id="@+id/ad_parent_view"
a:layout_width="match_parent" a:layout_width="match_parent"
a:layout_height="75px"/> a:layout_height="wrap_content"/>

View File

@ -17,6 +17,8 @@
a:layout_width="match_parent" a:layout_width="match_parent"
style="?fragmentTitleStyle"/> style="?fragmentTitleStyle"/>
<include layout="@layout/ad"/>
<ScrollView a:layout_width="match_parent" <ScrollView a:layout_width="match_parent"
a:layout_height="wrap_content"> a:layout_height="wrap_content">

View File

@ -16,6 +16,8 @@
a:layout_width="match_parent" a:layout_width="match_parent"
style="?fragmentTitleStyle"/> style="?fragmentTitleStyle"/>
<include layout="@layout/ad"/>
<ScrollView a:layout_width="match_parent" <ScrollView a:layout_width="match_parent"
a:layout_height="match_parent"> a:layout_height="match_parent">

View File

@ -16,6 +16,8 @@
a:layout_width="match_parent" a:layout_width="match_parent"
style="?fragmentTitleStyle"/> style="?fragmentTitleStyle"/>
<include layout="@layout/ad"/>
<ScrollView a:layout_width="match_parent" <ScrollView a:layout_width="match_parent"
a:layout_height="match_parent"> a:layout_height="match_parent">

View File

@ -11,6 +11,8 @@
a:layout_width="match_parent" a:layout_width="match_parent"
style="?fragmentTitleStyle"/> style="?fragmentTitleStyle"/>
<include layout="@layout/ad"/>
<ListView style="?fragmentListViewStyle"/> <ListView style="?fragmentListViewStyle"/>
</LinearLayout> </LinearLayout>

View File

@ -11,6 +11,8 @@
a:layout_width="match_parent" a:layout_width="match_parent"
style="?fragmentTitleStyle"/> style="?fragmentTitleStyle"/>
<include layout="@layout/ad"/>
<ListView style="?fragmentListViewStyle"/> <ListView style="?fragmentListViewStyle"/>
</LinearLayout> </LinearLayout>

View File

@ -11,4 +11,7 @@
a:layout_width="match_parent" a:layout_width="match_parent"
style="?fragmentTitleStyle"/> style="?fragmentTitleStyle"/>
<include layout="@layout/ad"/>
</LinearLayout> </LinearLayout>

View File

@ -17,6 +17,8 @@
a:layout_width="match_parent" a:layout_width="match_parent"
style="?fragmentTitleStyle"/> style="?fragmentTitleStyle"/>
<include layout="@layout/ad"/>
<ListView style="?fragmentListViewStyle"/> <ListView style="?fragmentListViewStyle"/>
</LinearLayout> </LinearLayout>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org
-->
<menu xmlns:a="http://schemas.android.com/apk/res/android">
<item a:id="@+id/menu_plot_settings"
a:title="@string/c_settings"
a:icon="@drawable/ab_settings"
a:showAsAction="always"/>
</menu>

View File

@ -10,5 +10,6 @@
<item a:id="@+id/var_menu_add_var" <item a:id="@+id/var_menu_add_var"
a:title="@string/c_add" a:title="@string/c_add"
a:icon="@drawable/ab_add"
a:showAsAction="always"/> a:showAsAction="always"/>
</menu> </menu>

View File

@ -201,11 +201,22 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
@Override @Override
public void setFragment(@NotNull SherlockFragmentActivity activity, @NotNull CalculatorFragmentType fragmentType, @Nullable Bundle fragmentArgs, int parentViewId) { public void setFragment(@NotNull SherlockFragmentActivity activity, @NotNull CalculatorFragmentType fragmentType, @Nullable Bundle fragmentArgs, int parentViewId) {
final Fragment fragment = Fragment.instantiate(activity, fragmentType.getFragmentClass().getName(), fragmentArgs);
final FragmentManager fm = activity.getSupportFragmentManager(); final FragmentManager fm = activity.getSupportFragmentManager();
final FragmentTransaction ft = fm.beginTransaction();
ft.add(parentViewId, fragment); Fragment fragment = fm.findFragmentByTag(fragmentType.getFragmentTag());
ft.commit(); if (fragment == null) {
fragment = Fragment.instantiate(activity, fragmentType.getFragmentClass().getName(), fragmentArgs);
final FragmentTransaction ft = fm.beginTransaction();
ft.add(parentViewId, fragment, fragmentType.getFragmentTag());
ft.commit();
} else {
if ( fragment.isDetached() ) {
final FragmentTransaction ft = fm.beginTransaction();
ft.attach(fragment);
ft.commit();
}
}
} }
@Override @Override

View File

@ -9,7 +9,6 @@ import com.google.ads.AdView;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.solovyev.android.ads.AdsController; import org.solovyev.android.ads.AdsController;
import org.solovyev.android.calculator.plot.CalculatorPlotFragment;
/** /**
* User: serso * User: serso
@ -89,11 +88,13 @@ public class CalculatorFragmentHelperImpl extends AbstractCalculatorHelper imple
@Override @Override
public void onViewCreated(@NotNull Fragment fragment, @NotNull View root) { public void onViewCreated(@NotNull Fragment fragment, @NotNull View root) {
final ViewGroup adParentView = (ViewGroup) root.findViewById(R.id.ad_parent_view);
final ViewGroup mainFragmentLayout = (ViewGroup) root.findViewById(R.id.main_fragment_layout); final ViewGroup mainFragmentLayout = (ViewGroup) root.findViewById(R.id.main_fragment_layout);
if (mainFragmentLayout != null) {
if (!(fragment instanceof CalculatorPlotFragment)) { if (adParentView != null) {
adView = AdsController.getInstance().inflateAd(fragment.getActivity(), mainFragmentLayout, R.id.main_fragment_layout); adView = AdsController.getInstance().inflateAd(fragment.getActivity(), adParentView, R.id.ad_parent_view);
} } else if ( mainFragmentLayout != null ) {
adView = AdsController.getInstance().inflateAd(fragment.getActivity(), mainFragmentLayout, R.id.main_fragment_layout);
} }
processButtons(fragment.getActivity(), root); processButtons(fragment.getActivity(), root);

View File

@ -35,7 +35,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.*;
import org.solovyev.android.menu.ActivityMenu; import org.solovyev.android.menu.ActivityMenu;
import org.solovyev.android.menu.LabeledMenuItem; import org.solovyev.android.menu.IdentifiableMenuItem;
import org.solovyev.android.menu.ListActivityMenu; import org.solovyev.android.menu.ListActivityMenu;
import org.solovyev.android.sherlock.menu.SherlockMenuHelper; import org.solovyev.android.sherlock.menu.SherlockMenuHelper;
import org.solovyev.common.MutableObject; import org.solovyev.common.MutableObject;
@ -83,16 +83,16 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
@NotNull @NotNull
private PreparedInput preparedInput; private PreparedInput preparedInput;
@Nullable
private Input input;
@NotNull @NotNull
private CalculatorEventData lastCalculatorEventData = CalculatorUtils.createFirstEventDataId(); private CalculatorEventData lastCalculatorEventData = CalculatorUtils.createFirstEventDataId();
private int bgColor; private int bgColor;
@Nullable
private PlotBoundaries plotBoundaries = null;
@NotNull @NotNull
private ActivityMenu<Menu, MenuItem> fragmentMenu = ListActivityMenu.fromList(PlotMenu.class, SherlockMenuHelper.getInstance()); private ActivityMenu<Menu, MenuItem> fragmentMenu = ListActivityMenu.fromResource(R.menu.plot_menu, PlotMenu.class, SherlockMenuHelper.getInstance());
public CalculatorPlotFragment() { public CalculatorPlotFragment() {
super(CalculatorApplication.getInstance().createFragmentHelper(R.layout.plot_fragment, R.string.c_graph, false)); super(CalculatorApplication.getInstance().createFragmentHelper(R.layout.plot_fragment, R.string.c_graph, false));
@ -104,25 +104,21 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
final Bundle arguments = getArguments(); final Bundle arguments = getArguments();
Input input = null;
if (arguments != null) { if (arguments != null) {
input = (Input) arguments.getSerializable(INPUT); input = (Input) arguments.getSerializable(INPUT);
} }
if (input == null) { if (input == null) {
this.preparedInput = prepareInputFromDisplay(CalculatorLocatorImpl.getInstance().getDisplay().getViewState());
this.bgColor = getResources().getColor(R.color.pane_background); this.bgColor = getResources().getColor(R.color.pane_background);
} else { } else {
this.preparedInput = prepareInput(input, true);
this.bgColor = getResources().getColor(android.R.color.transparent); this.bgColor = getResources().getColor(android.R.color.transparent);
} }
setRetainInstance(true);
setHasOptionsMenu(true); setHasOptionsMenu(true);
} }
@NotNull @NotNull
private static PreparedInput prepareInputFromDisplay(@NotNull CalculatorDisplayViewState displayState) { private static PreparedInput prepareInputFromDisplay(@NotNull CalculatorDisplayViewState displayState, @Nullable Bundle savedInstanceState) {
try { try {
if (displayState.isValid() && displayState.getResult() != null) { if (displayState.isValid() && displayState.getResult() != null) {
final Generic expression = displayState.getResult(); final Generic expression = displayState.getResult();
@ -130,7 +126,7 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
final Constant constant = CollectionsUtils.getFirstCollectionElement(CalculatorUtils.getNotSystemConstants(expression)); final Constant constant = CollectionsUtils.getFirstCollectionElement(CalculatorUtils.getNotSystemConstants(expression));
final Input input = new Input(expression.toString(), constant.getName()); final Input input = new Input(expression.toString(), constant.getName());
return prepareInput(input, false); return prepareInput(input, false, savedInstanceState);
} }
} }
} catch (RuntimeException e) { } catch (RuntimeException e) {
@ -141,7 +137,7 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
} }
@NotNull @NotNull
private static PreparedInput prepareInput(@NotNull Input input, boolean fromInputArgs) { private static PreparedInput prepareInput(@NotNull Input input, boolean fromInputArgs, @Nullable Bundle savedInstanceState) {
PreparedInput result; PreparedInput result;
try { try {
@ -149,7 +145,12 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
final Generic expression = Expression.valueOf(preparedExpression.getExpression()); final Generic expression = Expression.valueOf(preparedExpression.getExpression());
final Constant variable = new Constant(input.getVariableName()); final Constant variable = new Constant(input.getVariableName());
result = PreparedInput.newInstance(input, expression, variable, fromInputArgs); PlotBoundaries plotBoundaries = null;
if ( savedInstanceState != null ) {
plotBoundaries = (PlotBoundaries)savedInstanceState.getSerializable(PLOT_BOUNDARIES);
}
result = PreparedInput.newInstance(input, expression, variable, fromInputArgs, plotBoundaries);
} catch (ParseException e) { } catch (ParseException e) {
result = PreparedInput.newErrorInstance(fromInputArgs); result = PreparedInput.newErrorInstance(fromInputArgs);
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(e); CalculatorLocatorImpl.getInstance().getNotifier().showMessage(e);
@ -174,20 +175,13 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
} }
@Override @Override
public void onViewCreated(View root, Bundle savedInstanceState) { public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState); super.onViewCreated(view, savedInstanceState);
if (input == null) {
/*if ( savedInstanceState != null ) { this.preparedInput = prepareInputFromDisplay(CalculatorLocatorImpl.getInstance().getDisplay().getViewState(), savedInstanceState);
final Object object = savedInstanceState.getSerializable(PLOT_BOUNDARIES); } else {
if ( object instanceof PlotBoundaries) { this.preparedInput = prepareInput(input, true, savedInstanceState);
plotBoundaries = ((PlotBoundaries) object);
}
}*/
if (preparedInput.isFromInputArgs()) {
createChart();
createGraphicalView(root, null);
} }
} }
@ -204,12 +198,8 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if (!preparedInput.isFromInputArgs()) {
this.preparedInput = prepareInputFromDisplay(CalculatorLocatorImpl.getInstance().getDisplay().getViewState());
}
createChart(); createChart();
createGraphicalView(getView(), plotBoundaries); createGraphicalView(getView(), this.preparedInput.getPlotBoundaries());
} }
private void createGraphicalView(@NotNull View root, @Nullable PlotBoundaries plotBoundaries) { private void createGraphicalView(@NotNull View root, @Nullable PlotBoundaries plotBoundaries) {
@ -342,14 +332,12 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
Toast.makeText(CalculatorPlotFragment.this.getActivity(), "Arithmetic error: " + e.getLocalizedMessage(), Toast.LENGTH_LONG).show(); Toast.makeText(CalculatorPlotFragment.this.getActivity(), "Arithmetic error: " + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
} }
if (pendingOperation.getObject() == this) { uiHandler.post(new Runnable() {
uiHandler.post(new Runnable() { @Override
@Override public void run() {
public void run() { graphicalView.repaint();
graphicalView.repaint(); }
} });
});
}
} }
}); });
} }
@ -371,7 +359,7 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
if (calculatorEventData.isAfter(this.lastCalculatorEventData)) { if (calculatorEventData.isAfter(this.lastCalculatorEventData)) {
this.lastCalculatorEventData = calculatorEventData; this.lastCalculatorEventData = calculatorEventData;
this.preparedInput = prepareInputFromDisplay(((CalculatorDisplayChangeEventData) data).getNewValue()); this.preparedInput = prepareInputFromDisplay(((CalculatorDisplayChangeEventData) data).getNewValue(), null);
createChart(); createChart();
@ -380,7 +368,7 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
public void run() { public void run() {
final View view = getView(); final View view = getView();
if (view != null) { if (view != null) {
createGraphicalView(view, null); createGraphicalView(view, preparedInput.getPlotBoundaries());
} }
} }
}); });
@ -389,11 +377,6 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
} }
} }
/*@Override
public Object onRetainNonConfigurationInstance() {
return new PlotBoundaries(chart.getRenderer());
}*/
/* public void zoomInClickHandler(@NotNull View v) { /* public void zoomInClickHandler(@NotNull View v) {
this.graphicalView.zoomIn(); this.graphicalView.zoomIn();
@ -444,25 +427,26 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
********************************************************************** **********************************************************************
*/ */
private static enum PlotMenu implements LabeledMenuItem<MenuItem> { private static enum PlotMenu implements IdentifiableMenuItem<MenuItem> {
preferences(R.string.c_settings) { preferences(R.id.menu_plot_settings) {
@Override @Override
public void onClick(@NotNull MenuItem data, @NotNull Context context) { public void onClick(@NotNull MenuItem data, @NotNull Context context) {
context.startActivity(new Intent(context, CalculatorPlotPreferenceActivity.class)); context.startActivity(new Intent(context, CalculatorPlotPreferenceActivity.class));
} }
}; };
private final int captionResId; private final int itemId;
private PlotMenu(int captionResId) { private PlotMenu(int itemId) {
this.captionResId = captionResId; this.itemId = itemId;
} }
@NotNull @NotNull
@Override @Override
public String getCaption(@NotNull Context context) { public Integer getItemId() {
return context.getString(captionResId); return itemId;
} }
} }
@ -507,17 +491,21 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
private boolean fromInputArgs; private boolean fromInputArgs;
@Nullable
private PlotBoundaries plotBoundaries = null;
private PreparedInput() { private PreparedInput() {
} }
@NotNull @NotNull
public static PreparedInput newInstance(@NotNull Input input, @NotNull Generic expression, @NotNull Constant variable, boolean fromInputArgs) { public static PreparedInput newInstance(@NotNull Input input, @NotNull Generic expression, @NotNull Constant variable, boolean fromInputArgs, @Nullable PlotBoundaries plotBoundaries) {
final PreparedInput result = new PreparedInput(); final PreparedInput result = new PreparedInput();
result.input = input; result.input = input;
result.expression = expression; result.expression = expression;
result.variable = variable; result.variable = variable;
result.fromInputArgs = fromInputArgs; result.fromInputArgs = fromInputArgs;
result.plotBoundaries = plotBoundaries;
return result; return result;
} }
@ -548,6 +536,11 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
return expression; return expression;
} }
@Nullable
public PlotBoundaries getPlotBoundaries() {
return plotBoundaries;
}
@Nullable @Nullable
public Constant getVariable() { public Constant getVariable() {
return variable; return variable;