Menu moved
This commit is contained in:
parent
77874dd5f8
commit
a6a29f3e77
@ -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);
|
||||
}
|
@ -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<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();
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user