Menu changes
This commit is contained in:
parent
6ed16bb26a
commit
fd2fc566e3
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" android:versionCode="75" android:versionName="1.2.37" package="org.solovyev.android.calculator">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" android:versionCode="75" android:versionName="1.2.34" package="org.solovyev.android.calculator">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8"/>
|
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8"/>
|
||||||
|
|
||||||
<application android:debuggable="false" android:hardwareAccelerated="false" android:icon="@drawable/icon" android:label="@string/c_app_name" android:name=".CalculatorApplication">
|
<application android:debuggable="true" android:hardwareAccelerated="false" android:icon="@drawable/icon" android:label="@string/c_app_name" android:name=".CalculatorApplication">
|
||||||
|
|
||||||
<activity android:label="@string/c_app_name" android:name=".CalculatorActivity" android:windowSoftInputMode="adjustPan">
|
<activity android:label="@string/c_app_name" android:name=".CalculatorActivity" android:windowSoftInputMode="adjustPan">
|
||||||
|
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package org.solovyev.android;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.solovyev.android.calculator.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 4/23/12
|
||||||
|
* Time: 1:56 PM
|
||||||
|
*/
|
||||||
|
public interface ActivityMenu {
|
||||||
|
|
||||||
|
public boolean onCreateOptionsMenu(@NotNull Activity activity, @NotNull Menu menu);
|
||||||
|
|
||||||
|
public boolean onOptionsItemSelected(@NotNull Activity activity, @NotNull MenuItem item);
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
package org.solovyev.android;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.solovyev.android.menu.AMenuItem;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 4/23/12
|
||||||
|
* Time: 1:57 PM
|
||||||
|
*/
|
||||||
|
public class LayoutActivityMenu implements ActivityMenu {
|
||||||
|
|
||||||
|
public final int menuLayoutId;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private List<LayoutMenuItem> menuItems;
|
||||||
|
|
||||||
|
private LayoutActivityMenu(int menuLayoutId) {
|
||||||
|
this.menuLayoutId = menuLayoutId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <E extends Enum & LayoutMenuItem> ActivityMenu newInstance(int menuLayoutId, @NotNull Class<E> enumMenuClass) {
|
||||||
|
final LayoutActivityMenu result = new LayoutActivityMenu(menuLayoutId);
|
||||||
|
|
||||||
|
result.menuItems = new ArrayList<LayoutMenuItem>(enumMenuClass.getEnumConstants().length);
|
||||||
|
|
||||||
|
Collections.addAll(result.menuItems, enumMenuClass.getEnumConstants());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ActivityMenu newInstance(int menuLayoutId, @NotNull List<LayoutMenuItem> menuItems) {
|
||||||
|
final LayoutActivityMenu result = new LayoutActivityMenu(menuLayoutId);
|
||||||
|
|
||||||
|
result.menuItems = menuItems;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(@NotNull Activity activity, @NotNull Menu menu) {
|
||||||
|
final MenuInflater menuInflater = activity.getMenuInflater();
|
||||||
|
menuInflater.inflate(menuLayoutId, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(@NotNull Activity activity, @NotNull MenuItem item) {
|
||||||
|
for (LayoutMenuItem menuItem : menuItems) {
|
||||||
|
if (menuItem.getItemId().equals(item.getItemId())) {
|
||||||
|
menuItem.onClick(item, activity);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return activity.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static interface LayoutMenuItem extends AMenuItem<MenuItem> {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
Integer getItemId();
|
||||||
|
}
|
||||||
|
}
|
@ -28,10 +28,7 @@ import net.robotmedia.billing.BillingController;
|
|||||||
import net.robotmedia.billing.IBillingObserver;
|
import net.robotmedia.billing.IBillingObserver;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.AndroidUtils;
|
import org.solovyev.android.*;
|
||||||
import org.solovyev.android.FontSizeAdjuster;
|
|
||||||
import org.solovyev.android.LocalBinder;
|
|
||||||
import org.solovyev.android.ResourceCache;
|
|
||||||
import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity;
|
import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistory;
|
import org.solovyev.android.calculator.history.CalculatorHistory;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryState;
|
import org.solovyev.android.calculator.history.CalculatorHistoryState;
|
||||||
@ -48,6 +45,9 @@ import org.solovyev.common.utils.history.HistoryAction;
|
|||||||
|
|
||||||
public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener, ServiceConnection {
|
public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener, ServiceConnection {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static final String TAG = "Calculator++";
|
||||||
|
|
||||||
private static final int HVGA_WIDTH_PIXELS = 320;
|
private static final int HVGA_WIDTH_PIXELS = 320;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -78,6 +78,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
@NotNull
|
@NotNull
|
||||||
private NumeralBaseButtons numeralBaseButtons = new NumeralBaseButtons();
|
private NumeralBaseButtons numeralBaseButtons = new NumeralBaseButtons();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private ActivityMenu menu = LayoutActivityMenu.newInstance(R.menu.main_menu, CalculatorMenu.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the activity is first created.
|
* Called when the activity is first created.
|
||||||
*/
|
*/
|
||||||
@ -581,45 +584,12 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
final MenuInflater menuInflater = getMenuInflater();
|
return this.menu.onCreateOptionsMenu(this, menu);
|
||||||
menuInflater.inflate(R.menu.main_menu, menu);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
boolean result;
|
return menu.onOptionsItemSelected(this, item);
|
||||||
|
|
||||||
switch (item.getItemId()) {
|
|
||||||
case R.id.main_menu_item_settings:
|
|
||||||
CalculatorActivityLauncher.showSettings(this);
|
|
||||||
result = true;
|
|
||||||
break;
|
|
||||||
case R.id.main_menu_item_history:
|
|
||||||
CalculatorActivityLauncher.showHistory(this);
|
|
||||||
result = true;
|
|
||||||
break;
|
|
||||||
case R.id.main_menu_item_about:
|
|
||||||
CalculatorActivityLauncher.showAbout(this);
|
|
||||||
result = true;
|
|
||||||
break;
|
|
||||||
case R.id.main_menu_item_help:
|
|
||||||
CalculatorActivityLauncher.showHelp(this);
|
|
||||||
result = true;
|
|
||||||
break;
|
|
||||||
case R.id.main_menu_conversion_tool:
|
|
||||||
new NumeralBaseConverterDialog(null).show(this);
|
|
||||||
result = true;
|
|
||||||
break;
|
|
||||||
case R.id.main_menu_item_exit:
|
|
||||||
this.finish();
|
|
||||||
result = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
result = super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,7 +21,7 @@ import org.solovyev.android.calculator.model.CalculatorParseException;
|
|||||||
import org.solovyev.android.calculator.model.TextProcessor;
|
import org.solovyev.android.calculator.model.TextProcessor;
|
||||||
import org.solovyev.android.calculator.view.NumeralBaseConverterDialog;
|
import org.solovyev.android.calculator.view.NumeralBaseConverterDialog;
|
||||||
import org.solovyev.android.calculator.view.TextHighlighter;
|
import org.solovyev.android.calculator.view.TextHighlighter;
|
||||||
import org.solovyev.android.menu.AMenuItem;
|
import org.solovyev.android.menu.LabeledMenuItem;
|
||||||
import org.solovyev.android.view.AutoResizeTextView;
|
import org.solovyev.android.view.AutoResizeTextView;
|
||||||
import org.solovyev.common.utils.CollectionsUtils;
|
import org.solovyev.common.utils.CollectionsUtils;
|
||||||
|
|
||||||
@ -35,18 +35,18 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
public class CalculatorDisplay extends AutoResizeTextView implements ICalculatorDisplay{
|
public class CalculatorDisplay extends AutoResizeTextView implements ICalculatorDisplay{
|
||||||
|
|
||||||
public static enum MenuItem implements AMenuItem<CalculatorDisplay> {
|
public static enum MenuItem implements LabeledMenuItem<CalculatorDisplay> {
|
||||||
|
|
||||||
copy(R.string.c_copy) {
|
copy(R.string.c_copy) {
|
||||||
@Override
|
@Override
|
||||||
public void doAction(@NotNull CalculatorDisplay data, @NotNull Context context) {
|
public void onClick(@NotNull CalculatorDisplay data, @NotNull Context context) {
|
||||||
CalculatorModel.copyResult(context, data);
|
CalculatorModel.copyResult(context, data);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
convert(R.string.c_convert) {
|
convert(R.string.c_convert) {
|
||||||
@Override
|
@Override
|
||||||
public void doAction(@NotNull CalculatorDisplay data, @NotNull Context context) {
|
public void onClick(@NotNull CalculatorDisplay data, @NotNull Context context) {
|
||||||
new NumeralBaseConverterDialog(data.getGenericResult().toString()).show(context);
|
new NumeralBaseConverterDialog(data.getGenericResult().toString()).show(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ public class CalculatorDisplay extends AutoResizeTextView implements ICalculator
|
|||||||
|
|
||||||
plot(R.string.c_plot) {
|
plot(R.string.c_plot) {
|
||||||
@Override
|
@Override
|
||||||
public void doAction(@NotNull CalculatorDisplay data, @NotNull Context context) {
|
public void onClick(@NotNull CalculatorDisplay data, @NotNull Context context) {
|
||||||
final Generic generic = data.getGenericResult();
|
final Generic generic = data.getGenericResult();
|
||||||
assert generic != null;
|
assert generic != null;
|
||||||
|
|
||||||
|
@ -0,0 +1,75 @@
|
|||||||
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.solovyev.android.LayoutActivityMenu;
|
||||||
|
import org.solovyev.android.calculator.view.NumeralBaseConverterDialog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 4/23/12
|
||||||
|
* Time: 2:25 PM
|
||||||
|
*/
|
||||||
|
enum CalculatorMenu implements LayoutActivityMenu.LayoutMenuItem {
|
||||||
|
|
||||||
|
settings(R.id.main_menu_item_settings){
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||||
|
CalculatorActivityLauncher.showSettings(context);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
history(R.id.main_menu_item_history) {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||||
|
CalculatorActivityLauncher.showHistory(context);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
about(R.id.main_menu_item_about) {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||||
|
CalculatorActivityLauncher.showAbout(context);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
help(R.id.main_menu_item_help) {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||||
|
CalculatorActivityLauncher.showHelp(context);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
conversion_tool( R.id.main_menu_conversion_tool) {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||||
|
new NumeralBaseConverterDialog(null).show(context);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
exit(R.id.main_menu_item_exit) {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||||
|
if (context instanceof Activity) {
|
||||||
|
((Activity) context).finish();
|
||||||
|
} else {
|
||||||
|
Log.e(CalculatorActivity.TAG, "Activity menu used with context");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final int menuItemId;
|
||||||
|
|
||||||
|
private CalculatorMenu (int menuItemId) {
|
||||||
|
this.menuItemId = menuItemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Integer getItemId() {
|
||||||
|
return menuItemId;
|
||||||
|
}
|
||||||
|
}
|
@ -19,7 +19,7 @@ import android.widget.TextView;
|
|||||||
import android.widget.Toast;
|
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.menu.AMenuItem;
|
import org.solovyev.android.menu.LabeledMenuItem;
|
||||||
import org.solovyev.common.utils.StringUtils;
|
import org.solovyev.common.utils.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,11 +27,11 @@ import org.solovyev.common.utils.StringUtils;
|
|||||||
* Date: 12/18/11
|
* Date: 12/18/11
|
||||||
* Time: 3:09 PM
|
* Time: 3:09 PM
|
||||||
*/
|
*/
|
||||||
public enum HistoryItemMenuItem implements AMenuItem<HistoryItemMenuData> {
|
public enum HistoryItemMenuItem implements LabeledMenuItem<HistoryItemMenuData> {
|
||||||
|
|
||||||
use(R.string.c_use) {
|
use(R.string.c_use) {
|
||||||
@Override
|
@Override
|
||||||
public void doAction(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
public void onClick(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
||||||
if (context instanceof AbstractHistoryActivity) {
|
if (context instanceof AbstractHistoryActivity) {
|
||||||
AbstractHistoryActivity.useHistoryItem(data.getHistoryState(), (AbstractHistoryActivity) context);
|
AbstractHistoryActivity.useHistoryItem(data.getHistoryState(), (AbstractHistoryActivity) context);
|
||||||
} else {
|
} else {
|
||||||
@ -42,7 +42,7 @@ public enum HistoryItemMenuItem implements AMenuItem<HistoryItemMenuData> {
|
|||||||
|
|
||||||
copy_expression(R.string.c_copy_expression) {
|
copy_expression(R.string.c_copy_expression) {
|
||||||
@Override
|
@Override
|
||||||
public void doAction(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
public void onClick(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
||||||
final CalculatorHistoryState calculatorHistoryState = data.getHistoryState();
|
final CalculatorHistoryState calculatorHistoryState = data.getHistoryState();
|
||||||
final String text = calculatorHistoryState.getEditorState().getText();
|
final String text = calculatorHistoryState.getEditorState().getText();
|
||||||
if (!StringUtils.isEmpty(text)) {
|
if (!StringUtils.isEmpty(text)) {
|
||||||
@ -55,7 +55,7 @@ public enum HistoryItemMenuItem implements AMenuItem<HistoryItemMenuData> {
|
|||||||
|
|
||||||
copy_result(R.string.c_copy_result) {
|
copy_result(R.string.c_copy_result) {
|
||||||
@Override
|
@Override
|
||||||
public void doAction(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
public void onClick(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
||||||
final CalculatorHistoryState calculatorHistoryState = data.getHistoryState();
|
final CalculatorHistoryState calculatorHistoryState = data.getHistoryState();
|
||||||
final String text = calculatorHistoryState.getDisplayState().getEditorState().getText();
|
final String text = calculatorHistoryState.getDisplayState().getEditorState().getText();
|
||||||
if (!StringUtils.isEmpty(text)) {
|
if (!StringUtils.isEmpty(text)) {
|
||||||
@ -68,7 +68,7 @@ public enum HistoryItemMenuItem implements AMenuItem<HistoryItemMenuData> {
|
|||||||
|
|
||||||
save(R.string.c_save) {
|
save(R.string.c_save) {
|
||||||
@Override
|
@Override
|
||||||
public void doAction(@NotNull final HistoryItemMenuData data, @NotNull final Context context) {
|
public void onClick(@NotNull final HistoryItemMenuData data, @NotNull final Context context) {
|
||||||
final CalculatorHistoryState historyState = data.getHistoryState();
|
final CalculatorHistoryState historyState = data.getHistoryState();
|
||||||
if (!historyState.isSaved()) {
|
if (!historyState.isSaved()) {
|
||||||
createEditHistoryDialog(data, context, true);
|
createEditHistoryDialog(data, context, true);
|
||||||
@ -80,7 +80,7 @@ public enum HistoryItemMenuItem implements AMenuItem<HistoryItemMenuData> {
|
|||||||
|
|
||||||
edit(R.string.c_edit) {
|
edit(R.string.c_edit) {
|
||||||
@Override
|
@Override
|
||||||
public void doAction(@NotNull final HistoryItemMenuData data, @NotNull final Context context) {
|
public void onClick(@NotNull final HistoryItemMenuData data, @NotNull final Context context) {
|
||||||
final CalculatorHistoryState historyState = data.getHistoryState();
|
final CalculatorHistoryState historyState = data.getHistoryState();
|
||||||
if (historyState.isSaved()) {
|
if (historyState.isSaved()) {
|
||||||
createEditHistoryDialog(data, context, false);
|
createEditHistoryDialog(data, context, false);
|
||||||
@ -92,7 +92,7 @@ public enum HistoryItemMenuItem implements AMenuItem<HistoryItemMenuData> {
|
|||||||
|
|
||||||
remove(R.string.c_remove) {
|
remove(R.string.c_remove) {
|
||||||
@Override
|
@Override
|
||||||
public void doAction(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
public void onClick(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
||||||
final CalculatorHistoryState historyState = data.getHistoryState();
|
final CalculatorHistoryState historyState = data.getHistoryState();
|
||||||
if (historyState.isSaved()) {
|
if (historyState.isSaved()) {
|
||||||
data.getAdapter().remove(historyState);
|
data.getAdapter().remove(historyState);
|
||||||
|
@ -24,6 +24,7 @@ import org.solovyev.android.calculator.R;
|
|||||||
import org.solovyev.android.calculator.model.AndroidMathRegistry;
|
import org.solovyev.android.calculator.model.AndroidMathRegistry;
|
||||||
import org.solovyev.android.menu.AMenuBuilder;
|
import org.solovyev.android.menu.AMenuBuilder;
|
||||||
import org.solovyev.android.menu.AMenuItem;
|
import org.solovyev.android.menu.AMenuItem;
|
||||||
|
import org.solovyev.android.menu.LabeledMenuItem;
|
||||||
import org.solovyev.android.menu.MenuImpl;
|
import org.solovyev.android.menu.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;
|
||||||
@ -117,10 +118,10 @@ public abstract class AbstractMathEntityListActivity<T extends MathEntity> exten
|
|||||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
final T item = (T) parent.getItemAtPosition(position);
|
final T item = (T) parent.getItemAtPosition(position);
|
||||||
|
|
||||||
final List<AMenuItem<T>> menuItems = getMenuItemsOnLongClick(item);
|
final List<LabeledMenuItem<T>> menuItems = getMenuItemsOnLongClick(item);
|
||||||
|
|
||||||
if (!menuItems.isEmpty()) {
|
if (!menuItems.isEmpty()) {
|
||||||
final AMenuBuilder<AMenuItem<T>, T> menuBuilder = AMenuBuilder.newInstance(AbstractMathEntityListActivity.this, MenuImpl.newInstance(menuItems));
|
final AMenuBuilder<LabeledMenuItem<T>, T> menuBuilder = AMenuBuilder.newInstance(AbstractMathEntityListActivity.this, MenuImpl.newInstance(menuItems));
|
||||||
menuBuilder.create(item).show();
|
menuBuilder.create(item).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +139,7 @@ public abstract class AbstractMathEntityListActivity<T extends MathEntity> exten
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected abstract List<AMenuItem<T>> getMenuItemsOnLongClick(@NotNull T item);
|
protected abstract List<LabeledMenuItem<T>> getMenuItemsOnLongClick(@NotNull T item);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
|
@ -16,6 +16,7 @@ import org.solovyev.android.calculator.CalculatorModel;
|
|||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
import org.solovyev.android.calculator.model.CalculatorEngine;
|
import org.solovyev.android.calculator.model.CalculatorEngine;
|
||||||
import org.solovyev.android.menu.AMenuItem;
|
import org.solovyev.android.menu.AMenuItem;
|
||||||
|
import org.solovyev.android.menu.LabeledMenuItem;
|
||||||
import org.solovyev.common.utils.StringUtils;
|
import org.solovyev.common.utils.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -29,10 +30,10 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class CalculatorFunctionsActivity extends AbstractMathEntityListActivity<Function> {
|
public class CalculatorFunctionsActivity extends AbstractMathEntityListActivity<Function> {
|
||||||
|
|
||||||
private static enum LongClickMenuItem implements AMenuItem<Function>{
|
private static enum LongClickMenuItem implements LabeledMenuItem<Function> {
|
||||||
use(R.string.c_use) {
|
use(R.string.c_use) {
|
||||||
@Override
|
@Override
|
||||||
public void doAction(@NotNull Function data, @NotNull Context context) {
|
public void onClick(@NotNull Function data, @NotNull Context context) {
|
||||||
CalculatorModel.instance.processDigitButtonAction(data.getName(), false);
|
CalculatorModel.instance.processDigitButtonAction(data.getName(), false);
|
||||||
if (context instanceof Activity) {
|
if (context instanceof Activity) {
|
||||||
((Activity) context).finish();
|
((Activity) context).finish();
|
||||||
@ -50,7 +51,7 @@ public class CalculatorFunctionsActivity extends AbstractMathEntityListActivity<
|
|||||||
|
|
||||||
copy_description(R.string.c_copy_description) {
|
copy_description(R.string.c_copy_description) {
|
||||||
@Override
|
@Override
|
||||||
public void doAction(@NotNull Function data, @NotNull Context context) {
|
public void onClick(@NotNull Function data, @NotNull Context context) {
|
||||||
final String text = CalculatorEngine.instance.getFunctionsRegistry().getDescription(context, data.getName());
|
final String text = CalculatorEngine.instance.getFunctionsRegistry().getDescription(context, data.getName());
|
||||||
if (!StringUtils.isEmpty(text)) {
|
if (!StringUtils.isEmpty(text)) {
|
||||||
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
||||||
@ -107,8 +108,8 @@ public class CalculatorFunctionsActivity extends AbstractMathEntityListActivity<
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected List<AMenuItem<Function>> getMenuItemsOnLongClick(@NotNull Function item) {
|
protected List<LabeledMenuItem<Function>> getMenuItemsOnLongClick(@NotNull Function item) {
|
||||||
List<AMenuItem<Function>> result = new ArrayList<AMenuItem<Function>>(Arrays.asList(LongClickMenuItem.values()));
|
List<LabeledMenuItem<Function>> result = new ArrayList<LabeledMenuItem<Function>>(Arrays.asList(LongClickMenuItem.values()));
|
||||||
|
|
||||||
if ( StringUtils.isEmpty(CalculatorEngine.instance.getFunctionsRegistry().getDescription(this, item.getName())) ) {
|
if ( StringUtils.isEmpty(CalculatorEngine.instance.getFunctionsRegistry().getDescription(this, item.getName())) ) {
|
||||||
result.remove(LongClickMenuItem.copy_description);
|
result.remove(LongClickMenuItem.copy_description);
|
||||||
|
@ -9,6 +9,7 @@ import org.solovyev.android.calculator.CalculatorModel;
|
|||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
import org.solovyev.android.calculator.model.CalculatorEngine;
|
import org.solovyev.android.calculator.model.CalculatorEngine;
|
||||||
import org.solovyev.android.menu.AMenuItem;
|
import org.solovyev.android.menu.AMenuItem;
|
||||||
|
import org.solovyev.android.menu.LabeledMenuItem;
|
||||||
import org.solovyev.common.utils.StringUtils;
|
import org.solovyev.common.utils.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -23,11 +24,11 @@ import java.util.List;
|
|||||||
|
|
||||||
public class CalculatorOperatorsActivity extends AbstractMathEntityListActivity<Operator> {
|
public class CalculatorOperatorsActivity extends AbstractMathEntityListActivity<Operator> {
|
||||||
|
|
||||||
private static enum LongClickMenuItem implements AMenuItem<Operator> {
|
private static enum LongClickMenuItem implements LabeledMenuItem<Operator> {
|
||||||
|
|
||||||
use(R.string.c_use) {
|
use(R.string.c_use) {
|
||||||
@Override
|
@Override
|
||||||
public void doAction(@NotNull Operator data, @NotNull Context context) {
|
public void onClick(@NotNull Operator data, @NotNull Context context) {
|
||||||
CalculatorModel.instance.processDigitButtonAction(data.getName(), false);
|
CalculatorModel.instance.processDigitButtonAction(data.getName(), false);
|
||||||
if (context instanceof Activity) {
|
if (context instanceof Activity) {
|
||||||
((Activity) context).finish();
|
((Activity) context).finish();
|
||||||
@ -37,7 +38,7 @@ public class CalculatorOperatorsActivity extends AbstractMathEntityListActivity<
|
|||||||
|
|
||||||
copy_description(R.string.c_copy_description) {
|
copy_description(R.string.c_copy_description) {
|
||||||
@Override
|
@Override
|
||||||
public void doAction(@NotNull Operator data, @NotNull Context context) {
|
public void onClick(@NotNull Operator data, @NotNull Context context) {
|
||||||
final String text = OperatorDescriptionGetter.instance.getDescription(context, data.getName());
|
final String text = OperatorDescriptionGetter.instance.getDescription(context, data.getName());
|
||||||
if (!StringUtils.isEmpty(text)) {
|
if (!StringUtils.isEmpty(text)) {
|
||||||
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
||||||
@ -60,8 +61,8 @@ public class CalculatorOperatorsActivity extends AbstractMathEntityListActivity<
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected List<AMenuItem<Operator>> getMenuItemsOnLongClick(@NotNull Operator item) {
|
protected List<LabeledMenuItem<Operator>> getMenuItemsOnLongClick(@NotNull Operator item) {
|
||||||
final List<AMenuItem<Operator>> result = new ArrayList<AMenuItem<Operator>>(Arrays.asList(LongClickMenuItem.values()));
|
final List<LabeledMenuItem<Operator>> result = new ArrayList<LabeledMenuItem<Operator>>(Arrays.asList(LongClickMenuItem.values()));
|
||||||
|
|
||||||
if ( StringUtils.isEmpty(OperatorDescriptionGetter.instance.getDescription(this, item.getName())) ) {
|
if ( StringUtils.isEmpty(OperatorDescriptionGetter.instance.getDescription(this, item.getName())) ) {
|
||||||
result.remove(LongClickMenuItem.copy_description);
|
result.remove(LongClickMenuItem.copy_description);
|
||||||
|
@ -26,7 +26,7 @@ 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.menu.AMenuItem;
|
import org.solovyev.android.menu.LabeledMenuItem;
|
||||||
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;
|
||||||
@ -42,10 +42,10 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class CalculatorVarsActivity extends AbstractMathEntityListActivity<IConstant> {
|
public class CalculatorVarsActivity extends AbstractMathEntityListActivity<IConstant> {
|
||||||
|
|
||||||
private static enum LongClickMenuItem implements AMenuItem<IConstant>{
|
private static enum LongClickMenuItem implements LabeledMenuItem<IConstant>{
|
||||||
use(R.string.c_use) {
|
use(R.string.c_use) {
|
||||||
@Override
|
@Override
|
||||||
public void doAction(@NotNull IConstant data, @NotNull Context context) {
|
public void onClick(@NotNull IConstant data, @NotNull Context context) {
|
||||||
CalculatorModel.instance.processDigitButtonAction(data.getName(), false);
|
CalculatorModel.instance.processDigitButtonAction(data.getName(), false);
|
||||||
if (context instanceof Activity) {
|
if (context instanceof Activity) {
|
||||||
((Activity) context).finish();
|
((Activity) context).finish();
|
||||||
@ -55,7 +55,7 @@ public class CalculatorVarsActivity extends AbstractMathEntityListActivity<ICons
|
|||||||
|
|
||||||
edit(R.string.c_edit) {
|
edit(R.string.c_edit) {
|
||||||
@Override
|
@Override
|
||||||
public void doAction(@NotNull IConstant data, @NotNull Context context) {
|
public void onClick(@NotNull IConstant data, @NotNull Context context) {
|
||||||
if (context instanceof AbstractMathEntityListActivity) {
|
if (context instanceof AbstractMathEntityListActivity) {
|
||||||
createEditVariableDialog((AbstractMathEntityListActivity<IConstant>)context, data, data.getName(), StringUtils.getNotEmpty(data.getValue(), ""), data.getDescription());
|
createEditVariableDialog((AbstractMathEntityListActivity<IConstant>)context, data, data.getName(), StringUtils.getNotEmpty(data.getValue(), ""), data.getDescription());
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ public class CalculatorVarsActivity extends AbstractMathEntityListActivity<ICons
|
|||||||
|
|
||||||
remove(R.string.c_remove) {
|
remove(R.string.c_remove) {
|
||||||
@Override
|
@Override
|
||||||
public void doAction(@NotNull IConstant data, @NotNull Context context) {
|
public void onClick(@NotNull IConstant data, @NotNull Context context) {
|
||||||
if (context instanceof AbstractMathEntityListActivity) {
|
if (context instanceof AbstractMathEntityListActivity) {
|
||||||
new MathEntityRemover<IConstant>(data, null, CalculatorEngine.instance.getVarsRegistry(), ((AbstractMathEntityListActivity<IConstant>) context)).showConfirmationDialog();
|
new MathEntityRemover<IConstant>(data, null, CalculatorEngine.instance.getVarsRegistry(), ((AbstractMathEntityListActivity<IConstant>) context)).showConfirmationDialog();
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ public class CalculatorVarsActivity extends AbstractMathEntityListActivity<ICons
|
|||||||
|
|
||||||
copy_value(R.string.c_copy_value) {
|
copy_value(R.string.c_copy_value) {
|
||||||
@Override
|
@Override
|
||||||
public void doAction(@NotNull IConstant data, @NotNull Context context) {
|
public void onClick(@NotNull IConstant data, @NotNull Context context) {
|
||||||
final String text = data.getValue();
|
final String text = data.getValue();
|
||||||
if (!StringUtils.isEmpty(text)) {
|
if (!StringUtils.isEmpty(text)) {
|
||||||
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
||||||
@ -84,7 +84,7 @@ public class CalculatorVarsActivity extends AbstractMathEntityListActivity<ICons
|
|||||||
|
|
||||||
copy_description(R.string.c_copy_description) {
|
copy_description(R.string.c_copy_description) {
|
||||||
@Override
|
@Override
|
||||||
public void doAction(@NotNull IConstant data, @NotNull Context context) {
|
public void onClick(@NotNull IConstant data, @NotNull Context context) {
|
||||||
final String text = CalculatorEngine.instance.getVarsRegistry().getDescription(context, data.getName());
|
final String text = CalculatorEngine.instance.getVarsRegistry().getDescription(context, data.getName());
|
||||||
if (!StringUtils.isEmpty(text)) {
|
if (!StringUtils.isEmpty(text)) {
|
||||||
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
||||||
@ -130,8 +130,8 @@ public class CalculatorVarsActivity extends AbstractMathEntityListActivity<ICons
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected List<AMenuItem<IConstant>> getMenuItemsOnLongClick(@NotNull IConstant item) {
|
protected List<LabeledMenuItem<IConstant>> getMenuItemsOnLongClick(@NotNull IConstant item) {
|
||||||
final List<AMenuItem<IConstant>> result = new ArrayList<AMenuItem<IConstant>>(Arrays.asList(LongClickMenuItem.values()));
|
final List<LabeledMenuItem<IConstant>> result = new ArrayList<LabeledMenuItem<IConstant>>(Arrays.asList(LongClickMenuItem.values()));
|
||||||
|
|
||||||
if ( item.isSystem() ) {
|
if ( item.isSystem() ) {
|
||||||
result.remove(LongClickMenuItem.edit);
|
result.remove(LongClickMenuItem.edit);
|
||||||
|
1
pom.xml
1
pom.xml
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<android.sdk.path>/home/ssolovyev/projects/org.solovyev/misc/lib/android-sdk-linux_x86</android.sdk.path>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
Loading…
Reference in New Issue
Block a user