android_calculator-5: App help
This commit is contained in:
@@ -415,6 +415,10 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
CalculatorActivityLauncher.showAbout(this);
|
||||
result = true;
|
||||
break;
|
||||
case R.id.main_menu_item_help:
|
||||
CalculatorActivityLauncher.showHelp(this);
|
||||
result = true;
|
||||
break;
|
||||
case R.id.main_menu_item_exit:
|
||||
this.finish();
|
||||
result = true;
|
||||
|
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.widget.Toast;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.help.HelpActivity;
|
||||
import org.solovyev.common.utils.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -17,6 +18,10 @@ public class CalculatorActivityLauncher {
|
||||
context.startActivity(new Intent(context, CalculatorHistoryActivity.class));
|
||||
}
|
||||
|
||||
public static void showHelp(@NotNull final Context context) {
|
||||
context.startActivity(new Intent(context, HelpActivity.class));
|
||||
}
|
||||
|
||||
public static void showSettings(@NotNull final Context context) {
|
||||
context.startActivity(new Intent(context, CalculatorPreferencesActivity.class));
|
||||
}
|
||||
|
@@ -10,7 +10,6 @@ import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import jscl.math.function.Function;
|
||||
import jscl.math.operator.Operator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.model.CalculatorEngine;
|
||||
@@ -37,7 +36,10 @@ public class CalculatorOperatorsActivity extends ListActivity {
|
||||
|
||||
setContentView(R.layout.operators);
|
||||
|
||||
adapter = new OperatorsArrayAdapter(this, R.layout.var, R.id.var_text, new ArrayList<Operator>(CalculatorEngine.instance.getOperatorsRegistry().getEntities()));
|
||||
List<Operator> elements = new ArrayList<Operator>();
|
||||
elements.addAll(CalculatorEngine.instance.getOperatorsRegistry().getEntities());
|
||||
elements.addAll(CalculatorEngine.instance.getPostfixFunctionsRegistry().getEntities());
|
||||
adapter = new OperatorsArrayAdapter(this, R.layout.var, R.id.var_text, elements);
|
||||
setListAdapter(adapter);
|
||||
|
||||
final ListView lv = getListView();
|
||||
@@ -82,7 +84,11 @@ public class CalculatorOperatorsActivity extends ListActivity {
|
||||
|
||||
final Operator operator = getItem(position);
|
||||
|
||||
final String operatorDescription = CalculatorEngine.instance.getOperatorsRegistry().getDescription(getContext(), operator.getName());
|
||||
String operatorDescription = CalculatorEngine.instance.getOperatorsRegistry().getDescription(getContext(), operator.getName());
|
||||
if (StringUtils.isEmpty(operatorDescription)) {
|
||||
operatorDescription = CalculatorEngine.instance.getPostfixFunctionsRegistry().getDescription(getContext(), operator.getName());
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(operatorDescription)) {
|
||||
TextView description = (TextView) result.findViewById(R.id.var_description);
|
||||
if (description == null) {
|
||||
|
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.help;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.TabActivity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.widget.TabHost;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 11/19/11
|
||||
* Time: 11:35 AM
|
||||
*/
|
||||
public class HelpActivity extends TabActivity {
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.help);
|
||||
|
||||
final TabHost tabHost = getTabHost();
|
||||
|
||||
createTab(tabHost, "faq", "Faq", HelpFaqActivity.class);
|
||||
createTab(tabHost, "hints", "Hints", HelpHintsActivity.class);
|
||||
createTab(tabHost, "screens", "Screens", HelpScreensActivity.class);
|
||||
|
||||
tabHost.setCurrentTab(0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void createTab(@NotNull TabHost tabHost,
|
||||
@NotNull String tabId,
|
||||
@NotNull String tabCaption,
|
||||
@NotNull Class<? extends Activity> activityClass) {
|
||||
|
||||
TabHost.TabSpec spec;
|
||||
|
||||
final Intent intent = new Intent().setClass(this, activityClass);
|
||||
|
||||
// Initialize a TabSpec for each tab and add it to the TabHost
|
||||
spec = tabHost.newTabSpec(tabId).setIndicator(tabCaption)
|
||||
.setContent(intent);
|
||||
|
||||
tabHost.addTab(spec);
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.help;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 11/19/11
|
||||
* Time: 11:37 AM
|
||||
*/
|
||||
public class HelpFaqActivity extends Activity {
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.help_faq);
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.help;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 11/19/11
|
||||
* Time: 11:37 AM
|
||||
*/
|
||||
public class HelpHintsActivity extends Activity {
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.help_hints);
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.help;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 11/19/11
|
||||
* Time: 11:38 AM
|
||||
*/
|
||||
public class HelpScreensActivity extends Activity {
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.help_screens);
|
||||
}
|
||||
}
|
@@ -7,7 +7,6 @@
|
||||
package org.solovyev.android.calculator.model;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.common.math.MathEntity;
|
||||
import org.solovyev.common.math.MathRegistry;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -18,7 +17,7 @@ import java.util.Map;
|
||||
* Date: 11/17/11
|
||||
* Time: 11:28 PM
|
||||
*/
|
||||
public class AndroidFunctionsMathRegistry<T extends MathEntity> extends AndroidMathRegistryImpl<T> {
|
||||
public class AndroidFunctionsMathRegistry extends AndroidMathRegistryImpl<jscl.math.function.Function> {
|
||||
|
||||
@NotNull
|
||||
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
||||
@@ -29,7 +28,7 @@ public class AndroidFunctionsMathRegistry<T extends MathEntity> extends AndroidM
|
||||
@NotNull
|
||||
private static final String FUNCTION_DESCRIPTION_PREFIX = "c_fun_description_";
|
||||
|
||||
public AndroidFunctionsMathRegistry(@NotNull MathRegistry<T> functionsRegistry) {
|
||||
public AndroidFunctionsMathRegistry(@NotNull MathRegistry<jscl.math.function.Function> functionsRegistry) {
|
||||
super(functionsRegistry, FUNCTION_DESCRIPTION_PREFIX);
|
||||
}
|
||||
|
||||
|
@@ -53,7 +53,6 @@ public abstract class AndroidMathRegistryImpl<T extends MathEntity> implements A
|
||||
if (substitute == null) {
|
||||
stringId = stringsCache.get(prefix + name);
|
||||
} else {
|
||||
// todo serso: think
|
||||
stringId = stringsCache.get(prefix + substitute);
|
||||
}
|
||||
|
||||
|
@@ -6,8 +6,8 @@
|
||||
|
||||
package org.solovyev.android.calculator.model;
|
||||
|
||||
import jscl.math.operator.Operator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.common.math.MathEntity;
|
||||
import org.solovyev.common.math.MathRegistry;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -18,7 +18,7 @@ import java.util.Map;
|
||||
* Date: 11/17/11
|
||||
* Time: 11:29 PM
|
||||
*/
|
||||
public class AndroidOperatorsMathRegistry<T extends MathEntity> extends AndroidMathRegistryImpl<T> {
|
||||
public class AndroidOperatorsMathRegistry extends AndroidMathRegistryImpl<Operator> {
|
||||
|
||||
@NotNull
|
||||
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
||||
@@ -34,7 +34,7 @@ public class AndroidOperatorsMathRegistry<T extends MathEntity> extends AndroidM
|
||||
@NotNull
|
||||
private static final String OPERATOR_DESCRIPTION_PREFIX = "c_op_description_";
|
||||
|
||||
protected AndroidOperatorsMathRegistry(@NotNull MathRegistry<T> functionsRegistry) {
|
||||
protected AndroidOperatorsMathRegistry(@NotNull MathRegistry<Operator> functionsRegistry) {
|
||||
super(functionsRegistry, OPERATOR_DESCRIPTION_PREFIX);
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.model;
|
||||
|
||||
import jscl.math.operator.Operator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.common.math.MathRegistry;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 11/19/11
|
||||
* Time: 1:48 PM
|
||||
*/
|
||||
public class AndroidPostfixFunctionsRegistry extends AndroidMathRegistryImpl<Operator> {
|
||||
|
||||
@NotNull
|
||||
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
||||
static {
|
||||
substitutes.put("%", "percent");
|
||||
substitutes.put("!", "factorial");
|
||||
substitutes.put("°", "degree");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static final String POSTFIX_FUNCTION_DESCRIPTION_PREFIX = "c_pf_description_";
|
||||
|
||||
protected AndroidPostfixFunctionsRegistry(@NotNull MathRegistry<Operator> functionsRegistry) {
|
||||
super(functionsRegistry, POSTFIX_FUNCTION_DESCRIPTION_PREFIX);
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Map<String, String> getSubstitutes() {
|
||||
return substitutes;
|
||||
}
|
||||
}
|
@@ -102,6 +102,11 @@ class AndroidVarsRegistryImpl implements AndroidVarsRegistry {
|
||||
add(builder);
|
||||
}
|
||||
|
||||
tryToAddAuxVar("x");
|
||||
tryToAddAuxVar("y");
|
||||
tryToAddAuxVar("t");
|
||||
tryToAddAuxVar("j");
|
||||
|
||||
|
||||
/*Log.d(AndroidVarsRegistry.class.getName(), vars.size() + " variables registered!");
|
||||
for (Var var : vars) {
|
||||
@@ -109,6 +114,12 @@ class AndroidVarsRegistryImpl implements AndroidVarsRegistry {
|
||||
}*/
|
||||
}
|
||||
|
||||
private void tryToAddAuxVar(@NotNull String name) {
|
||||
if ( !contains(name) ) {
|
||||
add(new Var.Builder(name, (String)null));
|
||||
}
|
||||
}
|
||||
|
||||
private Var.Builder createBuilder(@NotNull String varName, @NotNull String varValue) {
|
||||
final Var.Builder result;
|
||||
|
||||
|
@@ -9,6 +9,7 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import jscl.JsclMathEngine;
|
||||
import jscl.MathEngine;
|
||||
import jscl.math.function.Function;
|
||||
import jscl.math.operator.Operator;
|
||||
import jscl.text.ParseInterruptedException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -16,7 +17,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||
import org.solovyev.android.msg.AndroidMessage;
|
||||
import org.solovyev.common.NumberMapper;
|
||||
import org.solovyev.common.math.MathRegistry;
|
||||
import org.solovyev.common.msg.MessageRegistry;
|
||||
import org.solovyev.common.utils.MutableObject;
|
||||
import org.solovyev.common.utils.StringUtils;
|
||||
@@ -64,12 +64,12 @@ public enum CalculatorEngine {
|
||||
private final AndroidVarsRegistry varsRegister = new AndroidVarsRegistryImpl(engine.getConstantsRegistry());
|
||||
|
||||
@NotNull
|
||||
private final AndroidMathRegistry functionsRegistry = new AndroidFunctionsMathRegistry(engine.getFunctionsRegistry());
|
||||
private final AndroidMathRegistry<jscl.math.function.Function> functionsRegistry = new AndroidFunctionsMathRegistry(engine.getFunctionsRegistry());
|
||||
|
||||
@NotNull
|
||||
private final AndroidMathRegistry operatorsRegistry = new AndroidOperatorsMathRegistry(engine.getOperatorsRegistry());
|
||||
private final AndroidMathRegistry<Operator> operatorsRegistry = new AndroidOperatorsMathRegistry(engine.getOperatorsRegistry());
|
||||
|
||||
private final MathRegistry<Operator> postfixFunctionsRegistry = engine.getPostfixFunctionsRegistry();
|
||||
private final AndroidMathRegistry<Operator> postfixFunctionsRegistry = new AndroidPostfixFunctionsRegistry(engine.getPostfixFunctionsRegistry());
|
||||
|
||||
@NotNull
|
||||
private DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols(Locale.getDefault());
|
||||
@@ -294,17 +294,17 @@ public enum CalculatorEngine {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public AndroidMathRegistry getFunctionsRegistry() {
|
||||
public AndroidMathRegistry<Function> getFunctionsRegistry() {
|
||||
return functionsRegistry;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public AndroidMathRegistry getOperatorsRegistry() {
|
||||
public AndroidMathRegistry<Operator> getOperatorsRegistry() {
|
||||
return operatorsRegistry;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public MathRegistry<Operator> getPostfixFunctionsRegistry() {
|
||||
public AndroidMathRegistry<Operator> getPostfixFunctionsRegistry() {
|
||||
return postfixFunctionsRegistry;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user