diff --git a/calculatorpp/src/main/java/org/solovyev/android/ActivityMenu.java b/calculatorpp/src/main/java/org/solovyev/android/ActivityMenu.java deleted file mode 100644 index 0315fa7e..00000000 --- a/calculatorpp/src/main/java/org/solovyev/android/ActivityMenu.java +++ /dev/null @@ -1,20 +0,0 @@ -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); -} diff --git a/calculatorpp/src/main/java/org/solovyev/android/LayoutActivityMenu.java b/calculatorpp/src/main/java/org/solovyev/android/LayoutActivityMenu.java deleted file mode 100644 index 334cf129..00000000 --- a/calculatorpp/src/main/java/org/solovyev/android/LayoutActivityMenu.java +++ /dev/null @@ -1,73 +0,0 @@ -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 menuItems; - - private LayoutActivityMenu(int menuLayoutId) { - this.menuLayoutId = menuLayoutId; - } - - public static ActivityMenu newInstance(int menuLayoutId, @NotNull Class enumMenuClass) { - final LayoutActivityMenu result = new LayoutActivityMenu(menuLayoutId); - - result.menuItems = new ArrayList(enumMenuClass.getEnumConstants().length); - - Collections.addAll(result.menuItems, enumMenuClass.getEnumConstants()); - - return result; - } - - public static ActivityMenu newInstance(int menuLayoutId, @NotNull List 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 { - - @NotNull - Integer getItemId(); - } -} diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index 73e203cf..79e84d30 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -35,6 +35,8 @@ import org.solovyev.android.calculator.history.CalculatorHistoryState; import org.solovyev.android.calculator.model.CalculatorEngine; import org.solovyev.android.calculator.view.*; import org.solovyev.android.history.HistoryDragProcessor; +import org.solovyev.android.menu.ActivityMenu; +import org.solovyev.android.menu.ListActivityMenu; import org.solovyev.android.view.ColorButton; import org.solovyev.android.view.drag.*; import org.solovyev.common.utils.Announcer; @@ -79,7 +81,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh private NumeralBaseButtons numeralBaseButtons = new NumeralBaseButtons(); @NotNull - private ActivityMenu menu = LayoutActivityMenu.newInstance(R.menu.main_menu, CalculatorMenu.class); + private ActivityMenu menu = ListActivityMenu.newInstance(R.menu.main_menu, CalculatorMenu.class); /** * Called when the activity is first created. diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorMenu.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorMenu.java index 6cbdbd7d..c79df031 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorMenu.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorMenu.java @@ -5,15 +5,15 @@ 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; +import org.solovyev.android.menu.ActivityMenuItem; /** * User: serso * Date: 4/23/12 * Time: 2:25 PM */ -enum CalculatorMenu implements LayoutActivityMenu.LayoutMenuItem { +enum CalculatorMenu implements ActivityMenuItem { settings(R.id.main_menu_item_settings){ @Override