text + some fixes

This commit is contained in:
Sergey Solovyev 2011-12-24 19:14:29 +04:00
parent 7392c81dc7
commit c67de4117a
10 changed files with 186 additions and 19 deletions

View File

@ -134,7 +134,7 @@
<string name="c_expression_copied">Expression copied to the clipboard!</string> <string name="c_expression_copied">Expression copied to the clipboard!</string>
<string name="c_history_item_status">Status: </string> <string name="c_history_item_status">Status: </string>
<string name="c_history_item_comment">Comment: </string> <string name="c_history_item_comment">Comment: </string>
<string name="c_use_expression">Use</string> <string name="c_use">Use</string>
<string name="c_copy_expression">Copy expression</string> <string name="c_copy_expression">Copy expression</string>
<string name="c_copy_result">Copy result</string> <string name="c_copy_result">Copy result</string>
<string name="c_history_expression">Value</string> <string name="c_history_expression">Value</string>

View File

@ -134,7 +134,7 @@
<string name="c_expression_copied">Espressione copiato negli appunti!</string> <string name="c_expression_copied">Espressione copiato negli appunti!</string>
<string name="c_history_item_status">Stato: </string> <string name="c_history_item_status">Stato: </string>
<string name="c_history_item_comment">Commento: </string> <string name="c_history_item_comment">Commento: </string>
<string name="c_use_expression">Uso</string> <string name="c_use">Uso</string>
<string name="c_copy_expression">Copia espressione</string> <string name="c_copy_expression">Copia espressione</string>
<string name="c_copy_result">Copia risultato</string> <string name="c_copy_result">Copia risultato</string>
<string name="c_history_expression">Valore</string> <string name="c_history_expression">Valore</string>

View File

@ -134,7 +134,7 @@
<string name="c_expression_copied">Выражение скопировано в буфер!</string> <string name="c_expression_copied">Выражение скопировано в буфер!</string>
<string name="c_history_item_status">Статус: </string> <string name="c_history_item_status">Статус: </string>
<string name="c_history_item_comment">Комментарий: </string> <string name="c_history_item_comment">Комментарий: </string>
<string name="c_use_expression">Использовать</string> <string name="c_use">Использовать</string>
<string name="c_copy_expression">Копировать выражение</string> <string name="c_copy_expression">Копировать выражение</string>
<string name="c_copy_result">Копировать результат</string> <string name="c_copy_result">Копировать результат</string>
<string name="c_history_expression">Значение</string> <string name="c_history_expression">Значение</string>

View File

@ -134,7 +134,7 @@
<string name="c_expression_copied">Expression copied to the clipboard!</string> <string name="c_expression_copied">Expression copied to the clipboard!</string>
<string name="c_history_item_status">Status: </string> <string name="c_history_item_status">Status: </string>
<string name="c_history_item_comment">Comment: </string> <string name="c_history_item_comment">Comment: </string>
<string name="c_use_expression">Use</string> <string name="c_use">Use</string>
<string name="c_copy_expression">Copy expression</string> <string name="c_copy_expression">Copy expression</string>
<string name="c_copy_result">Copy result</string> <string name="c_copy_result">Copy result</string>
<string name="c_history_expression">Value</string> <string name="c_history_expression">Value</string>
@ -150,4 +150,7 @@
<string name="c_history_was_removed">History was successfully removed!</string> <string name="c_history_was_removed">History was successfully removed!</string>
<string name="c_history_saved">History was successfully saved!</string> <string name="c_history_saved">History was successfully saved!</string>
<string name="c_copy_description">Copy description</string>
<string name="c_copy_value">Copy value</string>
</resources> </resources>

View File

@ -14,6 +14,7 @@ import android.widget.TabHost;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.view.prefs.AndroidUtils;
/** /**
* User: serso * User: serso
@ -35,6 +36,8 @@ public class HelpActivity extends TabActivity {
createTab(tabHost, "screens", R.string.c_screens, HelpScreensActivity.class); createTab(tabHost, "screens", R.string.c_screens, HelpScreensActivity.class);
tabHost.setCurrentTab(0); tabHost.setCurrentTab(0);
AndroidUtils.centerAndWrapTabsFor(tabHost);
} }
private void createTab(@NotNull TabHost tabHost, private void createTab(@NotNull TabHost tabHost,

View File

@ -20,7 +20,6 @@ import android.widget.Toast;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.view.AMenuItem; import org.solovyev.android.view.AMenuItem;
import org.solovyev.android.view.prefs.ResourceCache;
import org.solovyev.common.utils.StringUtils; import org.solovyev.common.utils.StringUtils;
/** /**
@ -30,7 +29,7 @@ import org.solovyev.common.utils.StringUtils;
*/ */
public enum HistoryItemMenuItem implements AMenuItem<HistoryItemMenuData> { public enum HistoryItemMenuItem implements AMenuItem<HistoryItemMenuData> {
use(R.string.c_use_expression) { use(R.string.c_use) {
@Override @Override
public void doAction(@NotNull HistoryItemMenuData data, @NotNull Context context) { public void doAction(@NotNull HistoryItemMenuData data, @NotNull Context context) {
if (context instanceof AbstractHistoryActivity) { if (context instanceof AbstractHistoryActivity) {

View File

@ -20,6 +20,9 @@ import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorModel; import org.solovyev.android.calculator.CalculatorModel;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.model.AndroidMathRegistry; 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.math.MathEntity;
import org.solovyev.common.utils.EqualsTool; import org.solovyev.common.utils.EqualsTool;
import org.solovyev.common.utils.Filter; import org.solovyev.common.utils.Filter;
@ -101,8 +104,27 @@ public abstract class AbstractMathEntityListActivity<T extends MathEntity> exten
AbstractMathEntityListActivity.this.finish(); AbstractMathEntityListActivity.this.finish();
} }
}); });
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<AMenuItem<T>> menuItems = getMenuItemsOnLongClick(item);
if (!menuItems.isEmpty()) {
final AMenuBuilder<AMenuItem<T>, T> menuBuilder = AMenuBuilder.newInstance(AbstractMathEntityListActivity.this, MenuImpl.newInstance(menuItems));
menuBuilder.create(item).show();
} }
return true;
}
});
}
@NotNull
protected abstract List<AMenuItem<T>> getMenuItemsOnLongClick(@NotNull T item);
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();

View File

@ -6,12 +6,20 @@
package org.solovyev.android.calculator.math.edit; package org.solovyev.android.calculator.math.edit;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.text.ClipboardManager;
import jscl.math.function.Function; import jscl.math.function.Function;
import org.jetbrains.annotations.NotNull; 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.calculator.model.CalculatorEngine;
import org.solovyev.android.view.AMenuItem;
import org.solovyev.common.utils.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
@ -21,6 +29,48 @@ import java.util.List;
*/ */
public class CalculatorFunctionsTabActivity extends AbstractMathEntityListActivity<Function> { public class CalculatorFunctionsTabActivity extends AbstractMathEntityListActivity<Function> {
private static enum LongClickMenuItem implements AMenuItem<Function>{
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"; public static final String CREATE_FUN_EXTRA_STRING = "org.solovyev.android.calculator.math.edit.CalculatorFunctionsTabActivity_create_fun";
@Override @Override
@ -55,6 +105,18 @@ public class CalculatorFunctionsTabActivity extends AbstractMathEntityListActivi
}*/ }*/
} }
@NotNull
@Override
protected List<AMenuItem<Function>> getMenuItemsOnLongClick(@NotNull Function item) {
List<AMenuItem<Function>> result = new ArrayList<AMenuItem<Function>>(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<Function> activity, /* private static void createEditVariableDialog(@NotNull final AbstractMathEntityListActivity<Function> activity,
@Nullable final CustomFunction function, @Nullable final CustomFunction function,
@Nullable final String name, @Nullable final String name,

View File

@ -4,9 +4,11 @@ import android.content.Context;
import jscl.math.operator.Operator; import jscl.math.operator.Operator;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.model.CalculatorEngine; import org.solovyev.android.calculator.model.CalculatorEngine;
import org.solovyev.android.view.AMenuItem;
import org.solovyev.common.utils.StringUtils; import org.solovyev.common.utils.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
@ -19,6 +21,12 @@ public class CalculatorOperatorsActivity extends AbstractMathEntityListActivity<
@NotNull @NotNull
@Override @Override
protected List<AMenuItem<Operator>> getMenuItemsOnLongClick(@NotNull Operator item) {
return Collections.emptyList();
}
@NotNull
@Override
protected MathEntityDescriptionGetter getDescriptionGetter() { protected MathEntityDescriptionGetter getDescriptionGetter() {
return new OperatorDescriptionGetter(); return new OperatorDescriptionGetter();
} }

View File

@ -6,28 +6,33 @@
package org.solovyev.android.calculator.math.edit; package org.solovyev.android.calculator.math.edit;
import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.text.ClipboardManager;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.view.*; import android.view.*;
import android.widget.AdapterView;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Toast; import android.widget.Toast;
import jscl.math.function.IConstant; import jscl.math.function.IConstant;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorModel;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.math.MathType; import org.solovyev.android.calculator.math.MathType;
import org.solovyev.android.calculator.model.CalculatorEngine; import org.solovyev.android.calculator.model.CalculatorEngine;
import org.solovyev.android.calculator.model.Var; import org.solovyev.android.calculator.model.Var;
import org.solovyev.android.view.AMenuItem;
import org.solovyev.common.utils.CollectionsUtils; import org.solovyev.common.utils.CollectionsUtils;
import org.solovyev.common.utils.Finder; import org.solovyev.common.utils.Finder;
import org.solovyev.common.utils.StringUtils; import org.solovyev.common.utils.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
@ -37,6 +42,60 @@ import java.util.List;
*/ */
public class CalculatorVarsTabActivity extends AbstractMathEntityListActivity<IConstant> { public class CalculatorVarsTabActivity extends AbstractMathEntityListActivity<IConstant> {
private static enum LongClickMenuItem implements AMenuItem<IConstant>{
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<IConstant>)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"; public static final String CREATE_VAR_EXTRA_STRING = "org.solovyev.android.calculator.math.edit.CalculatorVarsTabActivity_create_var";
@Override @Override
@ -48,15 +107,6 @@ public class CalculatorVarsTabActivity extends AbstractMathEntityListActivity<IC
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> 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(); final Intent intent = getIntent();
if (intent != null) { if (intent != null) {
final String varValue = intent.getStringExtra(CREATE_VAR_EXTRA_STRING); final String varValue = intent.getStringExtra(CREATE_VAR_EXTRA_STRING);
@ -69,6 +119,26 @@ public class CalculatorVarsTabActivity extends AbstractMathEntityListActivity<IC
} }
} }
@NotNull
@Override
protected List<AMenuItem<IConstant>> getMenuItemsOnLongClick(@NotNull IConstant item) {
final List<AMenuItem<IConstant>> result = new ArrayList<AMenuItem<IConstant>>(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 @NotNull
@Override @Override
protected MathEntityDescriptionGetter getDescriptionGetter() { protected MathEntityDescriptionGetter getDescriptionGetter() {