This commit is contained in:
Sergey Solovyev 2012-10-01 00:35:20 +04:00
parent e946b1547c
commit 2e7f4b632d
17 changed files with 1256 additions and 1120 deletions

View File

@ -80,10 +80,12 @@ public class CalculatorEditorImpl implements CalculatorEditor {
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData,
@NotNull CalculatorEventType calculatorEventType,
@Nullable Object data) {
if (calculatorEventType == CalculatorEventType.use_history_state) {
switch (calculatorEventType) {
case use_history_state:
final CalculatorHistoryState calculatorHistoryState = (CalculatorHistoryState)data;
final EditorHistoryState editorState = calculatorHistoryState.getEditorState();
this.setText(StringUtils.getNotEmpty(editorState.getText(), ""), editorState.getCursorPosition());
break;
}
}

View File

@ -89,7 +89,24 @@ public enum CalculatorEventType {
history_state_added,
// @NotNull CalculatorHistoryState
use_history_state;
use_history_state,
/*
**********************************************************************
*
* MATH ENTITIES
*
**********************************************************************
*/
// @NotNull IConstant
use_constant,
// @NotNull Function
use_function,
// @NotNull Operator
use_operator;
public boolean isOfType(@NotNull CalculatorEventType... types) {
for (CalculatorEventType type : types) {

View File

@ -4,6 +4,9 @@ import jscl.AbstractJsclArithmeticException;
import jscl.NumeralBase;
import jscl.NumeralBaseException;
import jscl.math.Generic;
import jscl.math.function.Function;
import jscl.math.function.IConstant;
import jscl.math.operator.Operator;
import jscl.text.ParseInterruptedException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -16,7 +19,8 @@ import org.solovyev.common.history.HistoryAction;
import org.solovyev.common.msg.MessageRegistry;
import org.solovyev.common.msg.MessageType;
import org.solovyev.common.text.StringUtils;
import org.solovyev.math.units.*;
import org.solovyev.math.units.ConversionException;
import org.solovyev.math.units.ConversionUtils;
import java.util.List;
import java.util.concurrent.Executor;
@ -381,9 +385,26 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
evaluate(JsclOperation.numeric, changeEventData.getNewState().getText(), calculatorEventData.getSequenceId());
}
break;
case engine_preferences_changed:
evaluate(calculatorEventData.getSequenceId());
break;
case use_constant:
final IConstant constant = (IConstant)data;
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(constant.getName());
break;
case use_operator:
final Operator operator = (Operator)data;
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(operator.getName());
break;
case use_function:
final Function function = (Function)data;
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(function.getName());
break;
}
}

View File

@ -41,6 +41,8 @@
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_functions" android:name=".math.edit.CalculatorFunctionsFragmentActivity"/>
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_operators" android:name=".math.edit.CalculatorOperatorsFragmentActivity"/>
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsFragmentActivity"/>
<activity android:label="@string/c_plot_graph" android:name=".plot.CalculatorPlotActivity"/>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@ -77,6 +77,10 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
activity.setContentView(layoutId);
CalculatorButtons.processButtons(true, theme, activity.getWindow().getDecorView());
if (savedInstanceState != null) {
navPosition = savedInstanceState.getInt(SELECTED_NAV, 0);
}
}
@Override
@ -89,10 +93,7 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
actionBar.setHomeButtonEnabled(false);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
if (savedInstanceState != null) {
navPosition = savedInstanceState.getInt(SELECTED_NAV, 0);
}
actionBar.setIcon(R.drawable.icon_action_bar);
}
@Override
@ -150,10 +151,14 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
final ActionBar.Tab tab = actionBar.newTab();
tab.setTag(tag);
tab.setText(captionResId);
tab.setTabListener(new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, parentViewId));
final ActionBarFragmentTabListener listener = new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, parentViewId);
tab.setTabListener(listener);
actionBar.addTab(tab);
fragmentTags.add(tag);
restoreSavedTab(activity);
}
@Override

View File

@ -10,10 +10,7 @@ import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.about.CalculatorAboutTabActivity;
import org.solovyev.android.calculator.help.CalculatorHelpTabActivity;
import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity;
import org.solovyev.android.calculator.math.edit.CalculatorFunctionsFragmentActivity;
import org.solovyev.android.calculator.math.edit.CalculatorOperatorsFragment;
import org.solovyev.android.calculator.math.edit.CalculatorVarsFragment;
import org.solovyev.android.calculator.math.edit.CalculatorVarsFragmentActivity;
import org.solovyev.android.calculator.math.edit.*;
import org.solovyev.android.calculator.plot.CalculatorPlotActivity;
import org.solovyev.android.calculator.plot.CalculatorPlotFragment;
import org.solovyev.common.text.StringUtils;
@ -46,7 +43,7 @@ public class CalculatorActivityLauncher {
}
public static void showOperators(@NotNull final Context context) {
context.startActivity(new Intent(context, CalculatorOperatorsFragment.class));
context.startActivity(new Intent(context, CalculatorOperatorsFragmentActivity.class));
}
public static void showVars(@NotNull final Context context) {

View File

@ -19,6 +19,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.*;
import org.solovyev.android.menu.AMenuBuilder;
import org.solovyev.android.menu.AMenuItem;
import org.solovyev.android.menu.LabeledMenuItem;
import org.solovyev.android.menu.MenuImpl;
import org.solovyev.common.equals.EqualsTool;
@ -105,9 +106,10 @@ public abstract class AbstractMathEntityListFragment<T extends MathEntity> exten
final View view,
final int position,
final long id) {
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(((MathEntity) parent.getItemAtPosition(position)).getName());
getActivity().finish();
final AMenuItem<T> onClick = getOnClickAction();
if ( onClick != null ) {
onClick.onClick(((T) parent.getItemAtPosition(position)), getActivity());
}
}
});
@ -128,6 +130,9 @@ public abstract class AbstractMathEntityListFragment<T extends MathEntity> exten
});
}
@Nullable
protected abstract AMenuItem<T> getOnClickAction();
protected abstract int getTitleResId();
@Override
@ -216,32 +221,35 @@ public abstract class AbstractMathEntityListFragment<T extends MathEntity> exten
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewGroup result = (ViewGroup) super.getView(position, convertView, parent);
public View getView(int position, @Nullable View convertView, ViewGroup parent) {
final ViewGroup result;
final T mathEntity = getItem(position);
if (convertView == null) {
result = (ViewGroup) super.getView(position, convertView, parent);
final String mathEntityDescription = descriptionGetter.getDescription(getContext(), mathEntity.getName());
if (!StringUtils.isEmpty(mathEntityDescription)) {
TextView description = (TextView) result.findViewById(R.id.math_entity_description);
if (description == null) {
final LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
final ViewGroup itemView = (ViewGroup) layoutInflater.inflate(R.layout.math_entity, null);
description = (TextView) itemView.findViewById(R.id.math_entity_description);
itemView.removeView(description);
result.addView(description);
}
description.setText(mathEntityDescription);
fillView(position, result);
} else {
TextView description = (TextView) result.findViewById(R.id.math_entity_description);
if (description != null) {
result.removeView(description);
}
result = (ViewGroup) convertView;
fillView(position, result);
}
return result;
}
private void fillView(int position, @NotNull ViewGroup result) {
final T mathEntity = getItem(position);
final String mathEntityDescription = descriptionGetter.getDescription(getContext(), mathEntity.getName());
if (!StringUtils.isEmpty(mathEntityDescription)) {
final TextView description = (TextView) result.findViewById(R.id.math_entity_description);
description.setVisibility(View.VISIBLE);
description.setText(mathEntityDescription);
} else {
final TextView description = (TextView) result.findViewById(R.id.math_entity_description);
description.setVisibility(View.GONE);
}
}
}
protected static class MathEntityDescriptionGetterImpl implements MathEntityDescriptionGetter {

View File

@ -12,8 +12,10 @@ import android.os.Bundle;
import android.text.ClipboardManager;
import jscl.math.function.Function;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.R;
import org.solovyev.android.menu.AMenuItem;
import org.solovyev.android.menu.LabeledMenuItem;
import org.solovyev.common.text.StringUtils;
@ -62,6 +64,11 @@ public class CalculatorFunctionsFragment extends AbstractMathEntityListFragment<
}*/
}
@Override
protected AMenuItem<Function> getOnClickAction() {
return LongClickMenuItem.use;
}
@Override
protected int getTitleResId() {
return R.string.c_functions;
@ -194,10 +201,7 @@ public class CalculatorFunctionsFragment extends AbstractMathEntityListFragment<
use(R.string.c_use) {
@Override
public void onClick(@NotNull Function data, @NotNull Context context) {
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(data.getName());
if (context instanceof Activity) {
((Activity) context).finish();
}
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_function, data);
}
},

View File

@ -58,6 +58,10 @@ public class CalculatorFunctionsFragmentActivity extends SherlockFragmentActivit
@Override
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
//To change body of implemented methods use File | Settings | File Templates.
switch (calculatorEventType) {
case use_function:
this.finish();
break;
}
}
}

View File

@ -5,8 +5,10 @@ import android.content.Context;
import android.text.ClipboardManager;
import jscl.math.operator.Operator;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.R;
import org.solovyev.android.menu.AMenuItem;
import org.solovyev.android.menu.LabeledMenuItem;
import org.solovyev.common.text.StringUtils;
@ -22,6 +24,11 @@ import java.util.List;
public class CalculatorOperatorsFragment extends AbstractMathEntityListFragment<Operator> {
@Override
protected AMenuItem<Operator> getOnClickAction() {
return LongClickMenuItem.use;
}
@Override
protected int getTitleResId() {
return R.string.c_operators;
@ -95,10 +102,7 @@ public class CalculatorOperatorsFragment extends AbstractMathEntityListFragment<
use(R.string.c_use) {
@Override
public void onClick(@NotNull Operator data, @NotNull Context context) {
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(data.getName());
if (context instanceof Activity) {
((Activity) context).finish();
}
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_operator, data);
}
},

View File

@ -0,0 +1,64 @@
/*
* 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
*/
package org.solovyev.android.calculator.math.edit;
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity;
/**
* User: serso
* Date: 12/21/11
* Time: 10:33 PM
*/
public class CalculatorOperatorsFragmentActivity extends SherlockFragmentActivity implements CalculatorEventListener {
@NotNull
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryFragmentActivity.class.getSimpleName());
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activityHelper.onCreate(this, savedInstanceState);
activityHelper.addTab(this, "operators", CalculatorOperatorsFragment.class, null, R.string.c_operators, R.id.main_layout);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
activityHelper.onSaveInstanceState(this, outState);
}
@Override
protected void onResume() {
super.onResume();
activityHelper.onResume(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
this.activityHelper.onDestroy(this);
}
@Override
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
switch (calculatorEventType) {
case use_operator:
this.finish();
break;
}
}
}

View File

@ -25,10 +25,12 @@ import com.actionbarsherlock.view.MenuItem;
import jscl.math.function.IConstant;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.math.MathType;
import org.solovyev.android.calculator.model.Var;
import org.solovyev.android.menu.AMenuItem;
import org.solovyev.android.menu.LabeledMenuItem;
import org.solovyev.common.JPredicate;
import org.solovyev.common.collections.CollectionsUtils;
@ -75,6 +77,11 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
return R.string.c_vars;
}
@Override
protected AMenuItem<IConstant> getOnClickAction() {
return LongClickMenuItem.use;
}
@NotNull
@Override
protected List<LabeledMenuItem<IConstant>> getMenuItemsOnLongClick(@NotNull IConstant item) {
@ -259,10 +266,7 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
use(R.string.c_use) {
@Override
public void onClick(@NotNull IConstant data, @NotNull Context context) {
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(data.getName());
if (context instanceof Activity) {
((Activity) context).finish();
}
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_constant, data);
}
},

View File

@ -80,6 +80,10 @@ public class CalculatorVarsFragmentActivity extends SherlockFragmentActivity imp
@Override
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
//To change body of implemented methods use File | Settings | File Templates.
switch (calculatorEventType) {
case use_constant:
this.finish();
break;
}
}
}