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"
a:id="@+id/ad_parent_view"
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"
style="?fragmentTitleStyle"/>
<include layout="@layout/ad"/>
<ScrollView a:layout_width="match_parent"
a:layout_height="wrap_content">

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -17,6 +17,8 @@
a:layout_width="match_parent"
style="?fragmentTitleStyle"/>
<include layout="@layout/ad"/>
<ListView style="?fragmentListViewStyle"/>
</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"
a:title="@string/c_add"
a:icon="@drawable/ab_add"
a:showAsAction="always"/>
</menu>

View File

@ -201,11 +201,22 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
@Override
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();
Fragment fragment = fm.findFragmentByTag(fragmentType.getFragmentTag());
if (fragment == null) {
fragment = Fragment.instantiate(activity, fragmentType.getFragmentClass().getName(), fragmentArgs);
final FragmentTransaction ft = fm.beginTransaction();
ft.add(parentViewId, fragment);
ft.add(parentViewId, fragment, fragmentType.getFragmentTag());
ft.commit();
} else {
if ( fragment.isDetached() ) {
final FragmentTransaction ft = fm.beginTransaction();
ft.attach(fragment);
ft.commit();
}
}
}
@Override

View File

@ -9,7 +9,6 @@ import com.google.ads.AdView;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.ads.AdsController;
import org.solovyev.android.calculator.plot.CalculatorPlotFragment;
/**
* User: serso
@ -89,12 +88,14 @@ public class CalculatorFragmentHelperImpl extends AbstractCalculatorHelper imple
@Override
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);
if (mainFragmentLayout != null) {
if (!(fragment instanceof CalculatorPlotFragment)) {
if (adParentView != null) {
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);

View File

@ -35,7 +35,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.*;
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.sherlock.menu.SherlockMenuHelper;
import org.solovyev.common.MutableObject;
@ -83,16 +83,16 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
@NotNull
private PreparedInput preparedInput;
@Nullable
private Input input;
@NotNull
private CalculatorEventData lastCalculatorEventData = CalculatorUtils.createFirstEventDataId();
private int bgColor;
@Nullable
private PlotBoundaries plotBoundaries = null;
@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() {
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();
Input input = null;
if (arguments != null) {
input = (Input) arguments.getSerializable(INPUT);
}
if (input == null) {
this.preparedInput = prepareInputFromDisplay(CalculatorLocatorImpl.getInstance().getDisplay().getViewState());
this.bgColor = getResources().getColor(R.color.pane_background);
} else {
this.preparedInput = prepareInput(input, true);
this.bgColor = getResources().getColor(android.R.color.transparent);
}
setRetainInstance(true);
setHasOptionsMenu(true);
}
@NotNull
private static PreparedInput prepareInputFromDisplay(@NotNull CalculatorDisplayViewState displayState) {
private static PreparedInput prepareInputFromDisplay(@NotNull CalculatorDisplayViewState displayState, @Nullable Bundle savedInstanceState) {
try {
if (displayState.isValid() && displayState.getResult() != null) {
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 Input input = new Input(expression.toString(), constant.getName());
return prepareInput(input, false);
return prepareInput(input, false, savedInstanceState);
}
}
} catch (RuntimeException e) {
@ -141,7 +137,7 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
}
@NotNull
private static PreparedInput prepareInput(@NotNull Input input, boolean fromInputArgs) {
private static PreparedInput prepareInput(@NotNull Input input, boolean fromInputArgs, @Nullable Bundle savedInstanceState) {
PreparedInput result;
try {
@ -149,7 +145,12 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
final Generic expression = Expression.valueOf(preparedExpression.getExpression());
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) {
result = PreparedInput.newErrorInstance(fromInputArgs);
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(e);
@ -174,20 +175,13 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
}
@Override
public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState);
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
/*if ( savedInstanceState != null ) {
final Object object = savedInstanceState.getSerializable(PLOT_BOUNDARIES);
if ( object instanceof PlotBoundaries) {
plotBoundaries = ((PlotBoundaries) object);
}
}*/
if (preparedInput.isFromInputArgs()) {
createChart();
createGraphicalView(root, null);
if (input == null) {
this.preparedInput = prepareInputFromDisplay(CalculatorLocatorImpl.getInstance().getDisplay().getViewState(), savedInstanceState);
} else {
this.preparedInput = prepareInput(input, true, savedInstanceState);
}
}
@ -204,12 +198,8 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
public void onResume() {
super.onResume();
if (!preparedInput.isFromInputArgs()) {
this.preparedInput = prepareInputFromDisplay(CalculatorLocatorImpl.getInstance().getDisplay().getViewState());
}
createChart();
createGraphicalView(getView(), plotBoundaries);
createGraphicalView(getView(), this.preparedInput.getPlotBoundaries());
}
private void createGraphicalView(@NotNull View root, @Nullable PlotBoundaries plotBoundaries) {
@ -342,7 +332,6 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
Toast.makeText(CalculatorPlotFragment.this.getActivity(), "Arithmetic error: " + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
if (pendingOperation.getObject() == this) {
uiHandler.post(new Runnable() {
@Override
public void run() {
@ -350,7 +339,6 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
}
});
}
}
});
}
}
@ -371,7 +359,7 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
if (calculatorEventData.isAfter(this.lastCalculatorEventData)) {
this.lastCalculatorEventData = calculatorEventData;
this.preparedInput = prepareInputFromDisplay(((CalculatorDisplayChangeEventData) data).getNewValue());
this.preparedInput = prepareInputFromDisplay(((CalculatorDisplayChangeEventData) data).getNewValue(), null);
createChart();
@ -380,7 +368,7 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
public void run() {
final View view = getView();
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) {
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
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
context.startActivity(new Intent(context, CalculatorPlotPreferenceActivity.class));
}
};
private final int captionResId;
private final int itemId;
private PlotMenu(int captionResId) {
this.captionResId = captionResId;
private PlotMenu(int itemId) {
this.itemId = itemId;
}
@NotNull
@Override
public String getCaption(@NotNull Context context) {
return context.getString(captionResId);
public Integer getItemId() {
return itemId;
}
}
@ -507,17 +491,21 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
private boolean fromInputArgs;
@Nullable
private PlotBoundaries plotBoundaries = null;
private PreparedInput() {
}
@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();
result.input = input;
result.expression = expression;
result.variable = variable;
result.fromInputArgs = fromInputArgs;
result.plotBoundaries = plotBoundaries;
return result;
}
@ -548,6 +536,11 @@ public class CalculatorPlotFragment extends CalculatorFragment implements Calcul
return expression;
}
@Nullable
public PlotBoundaries getPlotBoundaries() {
return plotBoundaries;
}
@Nullable
public Constant getVariable() {
return variable;