diff --git a/res/values-es/text_strings.xml b/res/values-es/text_strings.xml
index 40c5eb0e..462ac1fc 100644
--- a/res/values-es/text_strings.xml
+++ b/res/values-es/text_strings.xml
@@ -134,7 +134,7 @@
Expression copied to the clipboard!
Status:
Comment:
- Use
+ Use
Copy expression
Copy result
Value
diff --git a/res/values-it/text_strings.xml b/res/values-it/text_strings.xml
index a6343380..1054b4a9 100644
--- a/res/values-it/text_strings.xml
+++ b/res/values-it/text_strings.xml
@@ -134,7 +134,7 @@
Espressione copiato negli appunti!
Stato:
Commento:
- Uso
+ Uso
Copia espressione
Copia risultato
Valore
diff --git a/res/values-ru/text_strings.xml b/res/values-ru/text_strings.xml
index 1f6c79ef..a263d8e9 100644
--- a/res/values-ru/text_strings.xml
+++ b/res/values-ru/text_strings.xml
@@ -134,7 +134,7 @@
Выражение скопировано в буфер!
Статус:
Комментарий:
- Использовать
+ Использовать
Копировать выражение
Копировать результат
Значение
diff --git a/res/values/text_strings.xml b/res/values/text_strings.xml
index c8817764..d3eb9c6d 100644
--- a/res/values/text_strings.xml
+++ b/res/values/text_strings.xml
@@ -134,7 +134,7 @@
Expression copied to the clipboard!
Status:
Comment:
- Use
+ Use
Copy expression
Copy result
Value
@@ -150,4 +150,7 @@
History was successfully removed!
History was successfully saved!
+ Copy description
+ Copy value
+
\ No newline at end of file
diff --git a/src/main/java/org/solovyev/android/calculator/help/HelpActivity.java b/src/main/java/org/solovyev/android/calculator/help/HelpActivity.java
index b73192f0..85ec2f71 100644
--- a/src/main/java/org/solovyev/android/calculator/help/HelpActivity.java
+++ b/src/main/java/org/solovyev/android/calculator/help/HelpActivity.java
@@ -14,6 +14,7 @@ import android.widget.TabHost;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.R;
+import org.solovyev.android.view.prefs.AndroidUtils;
/**
* User: serso
@@ -35,6 +36,8 @@ public class HelpActivity extends TabActivity {
createTab(tabHost, "screens", R.string.c_screens, HelpScreensActivity.class);
tabHost.setCurrentTab(0);
+
+ AndroidUtils.centerAndWrapTabsFor(tabHost);
}
private void createTab(@NotNull TabHost tabHost,
diff --git a/src/main/java/org/solovyev/android/calculator/history/HistoryItemMenuItem.java b/src/main/java/org/solovyev/android/calculator/history/HistoryItemMenuItem.java
index 57ea2ec8..cd9304c7 100644
--- a/src/main/java/org/solovyev/android/calculator/history/HistoryItemMenuItem.java
+++ b/src/main/java/org/solovyev/android/calculator/history/HistoryItemMenuItem.java
@@ -20,7 +20,6 @@ import android.widget.Toast;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.R;
import org.solovyev.android.view.AMenuItem;
-import org.solovyev.android.view.prefs.ResourceCache;
import org.solovyev.common.utils.StringUtils;
/**
@@ -30,7 +29,7 @@ import org.solovyev.common.utils.StringUtils;
*/
public enum HistoryItemMenuItem implements AMenuItem {
- use(R.string.c_use_expression) {
+ use(R.string.c_use) {
@Override
public void doAction(@NotNull HistoryItemMenuData data, @NotNull Context context) {
if (context instanceof AbstractHistoryActivity) {
diff --git a/src/main/java/org/solovyev/android/calculator/math/edit/AbstractMathEntityListActivity.java b/src/main/java/org/solovyev/android/calculator/math/edit/AbstractMathEntityListActivity.java
index 6343c21b..5c2eb7fb 100644
--- a/src/main/java/org/solovyev/android/calculator/math/edit/AbstractMathEntityListActivity.java
+++ b/src/main/java/org/solovyev/android/calculator/math/edit/AbstractMathEntityListActivity.java
@@ -20,6 +20,9 @@ import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorModel;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.model.AndroidMathRegistry;
+import org.solovyev.android.view.AMenuBuilder;
+import org.solovyev.android.view.AMenuItem;
+import org.solovyev.android.view.MenuImpl;
import org.solovyev.common.math.MathEntity;
import org.solovyev.common.utils.EqualsTool;
import org.solovyev.common.utils.Filter;
@@ -101,9 +104,28 @@ public abstract class AbstractMathEntityListActivity exten
AbstractMathEntityListActivity.this.finish();
}
});
- }
- @Override
+ getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
+ @Override
+ public boolean onItemLongClick(AdapterView> parent, View view, int position, long id) {
+ final T item = (T) parent.getItemAtPosition(position);
+
+ final List> menuItems = getMenuItemsOnLongClick(item);
+
+ if (!menuItems.isEmpty()) {
+ final AMenuBuilder, T> menuBuilder = AMenuBuilder.newInstance(AbstractMathEntityListActivity.this, MenuImpl.newInstance(menuItems));
+ menuBuilder.create(item).show();
+ }
+
+ return true;
+ }
+ });
+ }
+
+ @NotNull
+ protected abstract List> getMenuItemsOnLongClick(@NotNull T item);
+
+ @Override
protected void onResume() {
super.onResume();
diff --git a/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorFunctionsTabActivity.java b/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorFunctionsTabActivity.java
index cf202f94..ab2395f6 100644
--- a/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorFunctionsTabActivity.java
+++ b/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorFunctionsTabActivity.java
@@ -6,12 +6,20 @@
package org.solovyev.android.calculator.math.edit;
+import android.app.Activity;
+import android.content.Context;
import android.os.Bundle;
+import android.text.ClipboardManager;
import jscl.math.function.Function;
import org.jetbrains.annotations.NotNull;
+import org.solovyev.android.calculator.CalculatorModel;
+import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.model.CalculatorEngine;
+import org.solovyev.android.view.AMenuItem;
+import org.solovyev.common.utils.StringUtils;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
/**
@@ -21,6 +29,48 @@ import java.util.List;
*/
public class CalculatorFunctionsTabActivity extends AbstractMathEntityListActivity {
+ private static enum LongClickMenuItem implements AMenuItem{
+ use(R.string.c_use) {
+ @Override
+ public void doAction(@NotNull Function data, @NotNull Context context) {
+ CalculatorModel.instance.processDigitButtonAction(data.getName(), false);
+ if (context instanceof Activity) {
+ ((Activity) context).finish();
+ }
+ }
+ },
+
+ /*edit(R.string.c_edit) {
+ @Override
+ public void doAction(@NotNull Function data, @NotNull Context context) {
+ if (context instanceof AbstractMathEntityListActivity) {
+ }
+ }
+ },*/
+
+ copy_description(R.string.c_copy_description) {
+ @Override
+ public void doAction(@NotNull Function data, @NotNull Context context) {
+ final String text = CalculatorEngine.instance.getFunctionsRegistry().getDescription(context, data.getName());
+ if (!StringUtils.isEmpty(text)) {
+ final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
+ clipboard.setText(text);
+ }
+ }
+ };
+ private final int captionId;
+
+ LongClickMenuItem(int captionId) {
+ this.captionId = captionId;
+ }
+
+ @NotNull
+ @Override
+ public String getCaption(@NotNull Context context) {
+ return context.getString(captionId);
+ }
+ }
+
public static final String CREATE_FUN_EXTRA_STRING = "org.solovyev.android.calculator.math.edit.CalculatorFunctionsTabActivity_create_fun";
@Override
@@ -55,6 +105,18 @@ public class CalculatorFunctionsTabActivity extends AbstractMathEntityListActivi
}*/
}
+ @NotNull
+ @Override
+ protected List> getMenuItemsOnLongClick(@NotNull Function item) {
+ List> result = new ArrayList>(Arrays.asList(LongClickMenuItem.values()));
+
+ if ( StringUtils.isEmpty(CalculatorEngine.instance.getFunctionsRegistry().getDescription(this, item.getName())) ) {
+ result.remove(LongClickMenuItem.copy_description);
+ }
+
+ return result;
+ }
+
/* private static void createEditVariableDialog(@NotNull final AbstractMathEntityListActivity activity,
@Nullable final CustomFunction function,
@Nullable final String name,
diff --git a/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorOperatorsActivity.java b/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorOperatorsActivity.java
index 2634d001..7740fa84 100644
--- a/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorOperatorsActivity.java
+++ b/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorOperatorsActivity.java
@@ -4,9 +4,11 @@ import android.content.Context;
import jscl.math.operator.Operator;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.model.CalculatorEngine;
+import org.solovyev.android.view.AMenuItem;
import org.solovyev.common.utils.StringUtils;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
/**
@@ -17,7 +19,13 @@ import java.util.List;
public class CalculatorOperatorsActivity extends AbstractMathEntityListActivity {
- @NotNull
+ @NotNull
+ @Override
+ protected List> getMenuItemsOnLongClick(@NotNull Operator item) {
+ return Collections.emptyList();
+ }
+
+ @NotNull
@Override
protected MathEntityDescriptionGetter getDescriptionGetter() {
return new OperatorDescriptionGetter();
diff --git a/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorVarsTabActivity.java b/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorVarsTabActivity.java
index 6d9f4e07..3c70770e 100644
--- a/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorVarsTabActivity.java
+++ b/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorVarsTabActivity.java
@@ -6,28 +6,33 @@
package org.solovyev.android.calculator.math.edit;
+import android.app.Activity;
import android.app.AlertDialog;
+import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
+import android.text.ClipboardManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.*;
-import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.Toast;
import jscl.math.function.IConstant;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import org.solovyev.android.calculator.CalculatorModel;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.math.MathType;
import org.solovyev.android.calculator.model.CalculatorEngine;
import org.solovyev.android.calculator.model.Var;
+import org.solovyev.android.view.AMenuItem;
import org.solovyev.common.utils.CollectionsUtils;
import org.solovyev.common.utils.Finder;
import org.solovyev.common.utils.StringUtils;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
/**
@@ -37,6 +42,60 @@ import java.util.List;
*/
public class CalculatorVarsTabActivity extends AbstractMathEntityListActivity {
+ private static enum LongClickMenuItem implements AMenuItem{
+ use(R.string.c_use) {
+ @Override
+ public void doAction(@NotNull IConstant data, @NotNull Context context) {
+ CalculatorModel.instance.processDigitButtonAction(data.getName(), false);
+ if (context instanceof Activity) {
+ ((Activity) context).finish();
+ }
+ }
+ },
+
+ edit(R.string.c_edit) {
+ @Override
+ public void doAction(@NotNull IConstant data, @NotNull Context context) {
+ if (context instanceof AbstractMathEntityListActivity) {
+ createEditVariableDialog((AbstractMathEntityListActivity)context, data, data.getName(), StringUtils.getNotEmpty(data.getValue(), ""), data.getDescription());
+ }
+ }
+ },
+
+ copy_value(R.string.c_copy_value) {
+ @Override
+ public void doAction(@NotNull IConstant data, @NotNull Context context) {
+ final String text = data.getValue();
+ if (!StringUtils.isEmpty(text)) {
+ final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
+ clipboard.setText(text);
+ }
+ }
+ },
+
+ copy_description(R.string.c_copy_description) {
+ @Override
+ public void doAction(@NotNull IConstant data, @NotNull Context context) {
+ final String text = CalculatorEngine.instance.getVarsRegistry().getDescription(context, data.getName());
+ if (!StringUtils.isEmpty(text)) {
+ final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
+ clipboard.setText(text);
+ }
+ }
+ };
+ private final int captionId;
+
+ LongClickMenuItem(int captionId) {
+ this.captionId = captionId;
+ }
+
+ @NotNull
+ @Override
+ public String getCaption(@NotNull Context context) {
+ return context.getString(captionId);
+ }
+ }
+
public static final String CREATE_VAR_EXTRA_STRING = "org.solovyev.android.calculator.math.edit.CalculatorVarsTabActivity_create_var";
@Override
@@ -48,15 +107,6 @@ public class CalculatorVarsTabActivity extends AbstractMathEntityListActivity parent, View view, int position, long id) {
- final IConstant iConstant = (IConstant) parent.getItemAtPosition(position);
- createEditVariableDialog(CalculatorVarsTabActivity.this, iConstant, iConstant.getName(), StringUtils.getNotEmpty(iConstant.getValue(), ""), iConstant.getDescription());
- return true;
- }
- });
-
final Intent intent = getIntent();
if (intent != null) {
final String varValue = intent.getStringExtra(CREATE_VAR_EXTRA_STRING);
@@ -69,6 +119,26 @@ public class CalculatorVarsTabActivity extends AbstractMathEntityListActivity> getMenuItemsOnLongClick(@NotNull IConstant item) {
+ final List> result = new ArrayList>(Arrays.asList(LongClickMenuItem.values()));
+
+ if ( item.isSystem() ) {
+ result.remove(LongClickMenuItem.edit);
+ }
+
+ if ( StringUtils.isEmpty(CalculatorEngine.instance.getVarsRegistry().getDescription(this, item.getName())) ) {
+ result.remove(LongClickMenuItem.copy_description);
+ }
+
+ if ( StringUtils.isEmpty(item.getValue()) ) {
+ result.remove(LongClickMenuItem.copy_value);
+ }
+
+ return result;
+ }
+
@NotNull
@Override
protected MathEntityDescriptionGetter getDescriptionGetter() {