DroidFish: Implemented configurable buttons.

This commit is contained in:
Peter Osterlund 2012-05-13 00:26:56 +00:00
parent 1a6d76c5e3
commit d67f536cf2
9 changed files with 507 additions and 50 deletions

View File

@ -20,18 +20,18 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/customButton"
android:contentDescription="@string/buttonDesc_custom"
android:id="@+id/custom2Button"
android:contentDescription="@string/buttonDesc_custom2"
android:layout_width="36dp"
android:layout_height="32dp"
android:src="@drawable/custom">
</ImageButton>
<ImageButton
android:id="@+id/flipButton"
android:contentDescription="@string/buttonDesc_flip"
android:id="@+id/custom1Button"
android:contentDescription="@string/buttonDesc_custom1"
android:layout_width="36dp"
android:layout_height="32dp"
android:src="@drawable/flip">
android:src="@drawable/custom">
</ImageButton>
<ImageButton
android:id="@+id/modeButton"

View File

@ -22,18 +22,18 @@
android:typeface="monospace"
android:textSize="10dip"/>
<ImageButton
android:id="@+id/customButton"
android:contentDescription="@string/buttonDesc_custom"
android:id="@+id/custom2Button"
android:contentDescription="@string/buttonDesc_custom2"
android:layout_width="36dp"
android:layout_height="32dp"
android:src="@drawable/custom">
</ImageButton>
<ImageButton
android:id="@+id/flipButton"
android:contentDescription="@string/buttonDesc_flip"
android:id="@+id/custom1Button"
android:contentDescription="@string/buttonDesc_custom1"
android:layout_width="36dp"
android:layout_height="32dp"
android:src="@drawable/flip">
android:src="@drawable/custom">
</ImageButton>
<ImageButton
android:id="@+id/modeButton"

View File

@ -15,18 +15,18 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/customButton"
android:contentDescription="@string/buttonDesc_custom"
android:id="@+id/custom2Button"
android:contentDescription="@string/buttonDesc_custom2"
android:layout_width="36dp"
android:layout_height="32dp"
android:src="@drawable/custom">
</ImageButton>
<ImageButton
android:id="@+id/flipButton"
android:contentDescription="@string/buttonDesc_flip"
android:id="@+id/custom1Button"
android:contentDescription="@string/buttonDesc_custom1"
android:layout_width="36dp"
android:layout_height="32dp"
android:src="@drawable/flip">
android:src="@drawable/custom">
</ImageButton>
<ImageButton
android:id="@+id/modeButton"

View File

@ -98,6 +98,13 @@ you are not actively using the program.\
<string name="load_next_game">Load Next Game</string>
<string name="no_prev_game">No previous game</string>
<string name="no_next_game">No next game</string>
<string name="select_action">Select Action</string>
<string name="flip_board">Flip Board</string>
<string name="toggle_show_thinking">Toggle Show Thinking</string>
<string name="toggle_book_hints">Toggle Book Hints</string>
<string name="toggle_pgn_variations">Toggle Variations</string>
<string name="toggle_pgn_comments">Toggle Comments</string>
<string name="toggle_pgn_headers">Toggle Headers</string>
<string name="cancel">Cancel</string>
<string name="yes">Yes</string>
<string name="no">No</string>
@ -249,6 +256,17 @@ you are not actively using the program.\
<string name="prefs_fontSize_summary">Font size for move list and game information</string>
<string name="prefs_largeButtons_title">Large Buttons</string>
<string name="prefs_largeButtons_summary">Use large buttons for game navigation and mode setting</string>
<string name="prefs_buttonSettings_title">Configure Buttons</string>
<string name="prefs_buttonSettings_summary">Configure button size and button actions.</string>
<string name="prefs_button_action_0_title">Main Action</string>
<string name="prefs_button_action_1_title">Menu Action 1</string>
<string name="prefs_button_action_2_title">Menu Action 2</string>
<string name="prefs_button_action_3_title">Menu Action 3</string>
<string name="prefs_button_action_4_title">Menu Action 4</string>
<string name="prefs_button_action_5_title">Menu Action 5</string>
<string name="prefs_button_action_6_title">Menu Action 6</string>
<string name="prefs_custom_button_1">Custom Button 1</string>
<string name="prefs_custom_button_2">Custom Button 2</string>
<string name="prefs_colors_title">Color Settings</string>
<string name="prefs_colors_summary">Change individual colors</string>
<string name="prefs_chess_board">Chess Board</string>
@ -321,8 +339,8 @@ you are not actively using the program.\
<string name="prefs_tbEngineProbe_summary">Enable tablebase probing in engine, when supported. Takes effect next time engine is started</string>
<string name="prefs_gtbPath_title">GTB Directory</string>
<string name="prefs_gtbPath_summary">Directory where Gaviota tablebases are installed. Leave blank to use default directory</string>
<string name="buttonDesc_custom">Custom button</string>
<string name="buttonDesc_flip">Flip board button</string>
<string name="buttonDesc_custom1">Custom button 1</string>
<string name="buttonDesc_custom2">Custom button 2</string>
<string name="buttonDesc_mode">Mode button</string>
<string name="buttonDesc_back">Backward button</string>
<string name="buttonDesc_forward">Forward button</string>
@ -480,4 +498,22 @@ you are not actively using the program.\
<item>50</item>
<item>1000000</item>
</string-array>
<string-array name="button_action_texts">
<item>Disabled</item>
<item>Flip Board</item>
<item>@string/toggle_show_thinking</item>
<item>@string/toggle_book_hints</item>
<item>@string/toggle_pgn_variations</item>
<item>@string/toggle_pgn_comments</item>
<item>@string/toggle_pgn_headers</item>
</string-array>
<string-array name="button_action_values">
<item></item>
<item>flipboard</item>
<item>showThinking</item>
<item>bookHints</item>
<item>viewVariations</item>
<item>viewComments</item>
<item>viewHeaders</item>
</string-array>
</resources>

View File

@ -172,12 +172,121 @@
android:entries="@array/font_size_texts"
android:defaultValue="@string/font_size_default">
</ListPreference>
<CheckBoxPreference
android:key="largeButtons"
android:title="@string/prefs_largeButtons_title"
android:summary="@string/prefs_largeButtons_summary"
android:defaultValue="false">
</CheckBoxPreference>
<PreferenceScreen
android:key="buttonSettings"
android:title="@string/prefs_buttonSettings_title"
android:summary="@string/prefs_buttonSettings_summary">
<CheckBoxPreference
android:key="largeButtons"
android:title="@string/prefs_largeButtons_title"
android:summary="@string/prefs_largeButtons_summary"
android:defaultValue="false">
</CheckBoxPreference>
<PreferenceCategory
android:title="@string/prefs_custom_button_1">
<ListPreference
android:key="button_action_custom1_0"
android:title="@string/prefs_button_action_0_title"
android:entryValues="@array/button_action_values"
android:entries="@array/button_action_texts"
android:defaultValue="flipboard">
</ListPreference>
<ListPreference
android:key="button_action_custom1_1"
android:title="@string/prefs_button_action_1_title"
android:entryValues="@array/button_action_values"
android:entries="@array/button_action_texts"
android:defaultValue="viewHeaders">
</ListPreference>
<ListPreference
android:key="button_action_custom1_2"
android:title="@string/prefs_button_action_2_title"
android:entryValues="@array/button_action_values"
android:entries="@array/button_action_texts"
android:defaultValue="viewComments">
</ListPreference>
<ListPreference
android:key="button_action_custom1_3"
android:title="@string/prefs_button_action_3_title"
android:entryValues="@array/button_action_values"
android:entries="@array/button_action_texts"
android:defaultValue="">
</ListPreference>
<ListPreference
android:key="button_action_custom1_4"
android:title="@string/prefs_button_action_4_title"
android:entryValues="@array/button_action_values"
android:entries="@array/button_action_texts"
android:defaultValue="">
</ListPreference>
<ListPreference
android:key="button_action_custom1_5"
android:title="@string/prefs_button_action_5_title"
android:entryValues="@array/button_action_values"
android:entries="@array/button_action_texts"
android:defaultValue="">
</ListPreference>
<ListPreference
android:key="button_action_custom1_6"
android:title="@string/prefs_button_action_6_title"
android:entryValues="@array/button_action_values"
android:entries="@array/button_action_texts"
android:defaultValue="">
</ListPreference>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/prefs_custom_button_2">
<ListPreference
android:key="button_action_custom2_0"
android:title="@string/prefs_button_action_0_title"
android:entryValues="@array/button_action_values"
android:entries="@array/button_action_texts"
android:defaultValue="">
</ListPreference>
<ListPreference
android:key="button_action_custom2_1"
android:title="@string/prefs_button_action_1_title"
android:entryValues="@array/button_action_values"
android:entries="@array/button_action_texts"
android:defaultValue="">
</ListPreference>
<ListPreference
android:key="button_action_custom2_2"
android:title="@string/prefs_button_action_2_title"
android:entryValues="@array/button_action_values"
android:entries="@array/button_action_texts"
android:defaultValue="">
</ListPreference>
<ListPreference
android:key="button_action_custom2_3"
android:title="@string/prefs_button_action_3_title"
android:entryValues="@array/button_action_values"
android:entries="@array/button_action_texts"
android:defaultValue="">
</ListPreference>
<ListPreference
android:key="button_action_custom2_4"
android:title="@string/prefs_button_action_4_title"
android:entryValues="@array/button_action_values"
android:entries="@array/button_action_texts"
android:defaultValue="">
</ListPreference>
<ListPreference
android:key="button_action_custom2_5"
android:title="@string/prefs_button_action_5_title"
android:entryValues="@array/button_action_values"
android:entries="@array/button_action_texts"
android:defaultValue="">
</ListPreference>
<ListPreference
android:key="button_action_custom2_6"
android:title="@string/prefs_button_action_6_title"
android:entryValues="@array/button_action_values"
android:entries="@array/button_action_texts"
android:defaultValue="">
</ListPreference>
</PreferenceCategory>
</PreferenceScreen>
<PreferenceScreen
android:key="colors"
android:title="@string/prefs_colors_title"

View File

@ -0,0 +1,25 @@
/*
DroidFish - An Android chess program.
Copyright (C) 2012 Peter Österlund, peterosterlund2@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.petero.droidfish;
public interface ActionFactory {
/** Create action given an action ID. */
public UIAction getAction(String actionId);
}

View File

@ -0,0 +1,132 @@
/*
DroidFish - An Android chess program.
Copyright (C) 2012 Peter Österlund, peterosterlund2@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.petero.droidfish;
import java.util.ArrayList;
import android.app.Activity;
import android.content.SharedPreferences;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.ImageButton;
/**
* Handle all actions connected to a button.
*/
public class ButtonActions {
private ImageButton button;
private String name;
private int longClickDialog;
private int menuTitle;
private UIAction mainAction = null;
private ArrayList<UIAction> menuActions = new ArrayList<UIAction>();
private static final int maxMenuActions = 6;
/** Constructor. */
public ButtonActions(String buttonName, int longClickDialog, int menuTitle) {
button = null;
name = buttonName;
this.longClickDialog = longClickDialog;
this.menuTitle = menuTitle;
}
/** Connect GUI button. */
public void setImageButton(ImageButton button, final Activity activity) {
this.button = button;
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mainAction != null) {
if (mainAction.enabled())
mainAction.run();
} else {
showMenu(activity);
}
}
});
button.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return showMenu(activity);
}
});
}
private boolean showMenu(Activity activity) {
boolean haveActions = false;
boolean haveEnabledActions = false;
for (UIAction a : menuActions) {
if (a != null) {
haveActions = true;
if (a.enabled())
haveEnabledActions = true;
}
}
if (haveActions) {
if (haveEnabledActions) {
activity.removeDialog(longClickDialog);
activity.showDialog(longClickDialog);
}
return true;
}
return false;
}
/** Get menu title resource. */
public int getMenuTitle() {
return menuTitle;
}
/** Get a menu action. */
public ArrayList<UIAction> getMenuActions() {
return menuActions;
}
/** Update button actions from preferences settings. */
public void readPrefs(SharedPreferences settings, ActionFactory factory) {
boolean visible = false;
String actionId = settings.getString("button_action_" + name + "_0", "");
mainAction = factory.getAction(actionId);
if (mainAction != null)
visible = true;
menuActions.clear();
for (int i = 0; i < maxMenuActions; i++) {
actionId = settings.getString("button_action_" + name + "_" + (i+1), "");
UIAction a = factory.getAction(actionId);
if (a != null)
visible = true;
menuActions.add(a);
}
if (button != null)
button.setVisibility(visible ? View.VISIBLE : View.GONE);
}
/** Get icon resource for button. */
public int getIcon(boolean large) {
int ret = -1;
if (mainAction != null)
ret = mainAction.getIcon(large);
if (ret == -1)
ret = large ? R.drawable.custom_large : R.drawable.custom;
return ret;
}
}

View File

@ -28,6 +28,7 @@ import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.TreeMap;
@ -166,7 +167,9 @@ public class DroidFish extends Activity implements GUIInterface {
private ScrollView moveListScroll;
private TextView moveList;
private TextView thinking;
private ImageButton custButton, flipButton, modeButton, undoButton, redoButton;
private ImageButton custom1Button, custom2Button;
private ImageButton modeButton, undoButton, redoButton;
private ButtonActions custom1ButtonActions, custom2ButtonActions;
private TextView whiteClock, blackClock, titleText;
SharedPreferences settings;
@ -195,6 +198,88 @@ public class DroidFish extends Activity implements GUIInterface {
private WakeLock wakeLock = null;
private boolean useWakeLock = false;
/** Defines all configurable button actions. */
private ActionFactory actionFactory = new ActionFactory() {
private HashMap<String, UIAction> actions;
private void addAction(UIAction a) {
actions.put(a.getId(), a);
}
{
actions = new HashMap<String, UIAction>();
addAction(new UIAction() {
public String getId() { return "flipboard"; }
public int getName() { return R.string.flip_board; }
public int getIcon(boolean large) { return large ? R.drawable.flip_large : R.drawable.flip; }
public boolean enabled() { return true; }
public void run() {
boardFlipped = !cb.flipped;
setBooleanPref("boardFlipped", boardFlipped);
cb.setFlipped(boardFlipped);
}
});
addAction(new UIAction() {
public String getId() { return "showThinking"; }
public int getName() { return R.string.toggle_show_thinking; }
public int getIcon(boolean large) { return -1; }
public boolean enabled() { return true; }
public void run() {
mShowThinking = toggleBooleanPref("showThinking");
updateThinkingInfo();
}
});
addAction(new UIAction() {
public String getId() { return "bookHints"; }
public int getName() { return R.string.toggle_book_hints; }
public int getIcon(boolean large) { return -1; }
public boolean enabled() { return true; }
public void run() {
mShowBookHints = toggleBooleanPref("bookHints");
updateThinkingInfo();
}
});
addAction(new UIAction() {
public String getId() { return "viewVariations"; }
public int getName() { return R.string.toggle_pgn_variations; }
public int getIcon(boolean large) { return -1; }
public boolean enabled() { return true; }
public void run() {
pgnOptions.view.variations = toggleBooleanPref("viewVariations");
gameTextListener.clear();
ctrl.prefsChanged();
}
});
addAction(new UIAction() {
public String getId() { return "viewComments"; }
public int getName() { return R.string.toggle_pgn_comments; }
public int getIcon(boolean large) { return -1; }
public boolean enabled() { return true; }
public void run() {
pgnOptions.view.comments = toggleBooleanPref("viewComments");
gameTextListener.clear();
ctrl.prefsChanged();
}
});
addAction(new UIAction() {
public String getId() { return "viewHeaders"; }
public int getName() { return R.string.toggle_pgn_headers; }
public int getIcon(boolean large) { return -1; }
public boolean enabled() { return true; }
public void run() {
pgnOptions.view.headers = toggleBooleanPref("viewHeaders");
gameTextListener.clear();
ctrl.prefsChanged();
}
});
}
@Override
public UIAction getAction(String actionId) {
return actions.get(actionId);
}
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
@ -204,6 +289,7 @@ public class DroidFish extends Activity implements GUIInterface {
createDirectories();
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
settings = PreferenceManager.getDefaultSharedPreferences(this);
settings.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {
@Override
@ -218,6 +304,11 @@ public class DroidFish extends Activity implements GUIInterface {
wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "droidfish");
wakeLock.setReferenceCounted(false);
custom1ButtonActions = new ButtonActions("custom1", CUSTOM1_BUTTON_DIALOG,
R.string.select_action);
custom2ButtonActions = new ButtonActions("custom2", CUSTOM2_BUTTON_DIALOG,
R.string.select_action);
initUI(true);
gameTextListener = new PgnScreenText(pgnOptions);
@ -479,20 +570,12 @@ public class DroidFish extends Activity implements GUIInterface {
}
});
custButton = (ImageButton)findViewById(R.id.customButton);
custButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
flipButton = (ImageButton)findViewById(R.id.flipButton);
flipButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
setBoardFlipPrefs(!cb.flipped);
cb.setFlipped(boardFlipped);
}
});
custom1Button = (ImageButton)findViewById(R.id.custom1Button);
custom1ButtonActions.setImageButton(custom1Button, this);
custom2Button = (ImageButton)findViewById(R.id.custom2Button);
custom2ButtonActions.setImageButton(custom2Button, this);
modeButton = (ImageButton)findViewById(R.id.modeButton);
modeButton.setOnClickListener(new OnClickListener() {
@Override
@ -631,6 +714,9 @@ public class DroidFish extends Activity implements GUIInterface {
vibrateEnabled = settings.getBoolean("vibrateEnabled", false);
animateMoves = settings.getBoolean("animateMoves", true);
custom1ButtonActions.readPrefs(settings, actionFactory);
custom2ButtonActions.readPrefs(settings, actionFactory);
boolean largeButtons = settings.getBoolean("largeButtons", false);
Resources r = getResources();
int bWidth = (int)Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 36, r.getDisplayMetrics()));
@ -638,26 +724,24 @@ public class DroidFish extends Activity implements GUIInterface {
if (largeButtons) {
bWidth = bWidth * 3 / 2;
bHeight = bHeight * 3 / 2;
custButton.setImageResource(R.drawable.custom_large);
flipButton.setImageResource(R.drawable.flip_large);
custom1Button.setImageResource(custom1ButtonActions.getIcon(true));
custom2Button.setImageResource(custom2ButtonActions.getIcon(true));
modeButton.setImageResource(R.drawable.mode_large);
undoButton.setImageResource(R.drawable.left_large);
redoButton.setImageResource(R.drawable.right_large);
} else {
custButton.setImageResource(R.drawable.custom);
flipButton.setImageResource(R.drawable.flip);
custom1Button.setImageResource(custom1ButtonActions.getIcon(false));
custom2Button.setImageResource(custom2ButtonActions.getIcon(false));
modeButton.setImageResource(R.drawable.mode);
undoButton.setImageResource(R.drawable.left);
redoButton.setImageResource(R.drawable.right);
}
custButton.setLayoutParams(new LinearLayout.LayoutParams(bWidth, bHeight));
flipButton.setLayoutParams(new LinearLayout.LayoutParams(bWidth, bHeight));
custom1Button.setLayoutParams(new LinearLayout.LayoutParams(bWidth, bHeight));
custom2Button.setLayoutParams(new LinearLayout.LayoutParams(bWidth, bHeight));
modeButton.setLayoutParams(new LinearLayout.LayoutParams(bWidth, bHeight));
undoButton.setLayoutParams(new LinearLayout.LayoutParams(bWidth, bHeight));
redoButton.setLayoutParams(new LinearLayout.LayoutParams(bWidth, bHeight));
custButton.setVisibility(true ? View.GONE : View.VISIBLE);
bookOptions.filename = settings.getString("bookFile", "");
bookOptions.maxLength = getIntSetting("bookMaxLength", 1000000);
bookOptions.preferMainLines = settings.getBoolean("bookPreferMainLines", false);
@ -954,13 +1038,20 @@ public class DroidFish extends Activity implements GUIInterface {
setBoardFlip(false);
}
private final void setBoardFlipPrefs(boolean flipped) {
boardFlipped = flipped;
/** Set a boolean preference setting. */
private final void setBooleanPref(String name, boolean value) {
Editor editor = settings.edit();
editor.putBoolean("boardFlipped", boardFlipped);
editor.putBoolean(name, value);
editor.commit();
}
/** Toggle a boolean preference setting. Return new value. */
private final boolean toggleBooleanPref(String name) {
boolean value = !settings.getBoolean(name, false);
setBooleanPref(name, value);
return value;
}
private final void setBoardFlip(boolean matchPlayerNames) {
boolean flipped = boardFlipped;
if (playerNameFlip && matchPlayerNames && (ctrl != null)) {
@ -971,7 +1062,8 @@ public class DroidFish extends Activity implements GUIInterface {
if (( flipped && (whiteMatch > blackMatch)) ||
(!flipped && (whiteMatch < blackMatch))) {
flipped = !flipped;
setBoardFlipPrefs(flipped);
boardFlipped = flipped;
setBooleanPref("boardFlipped", flipped);
}
}
if (autoSwapSides) {
@ -1222,6 +1314,8 @@ public class DroidFish extends Activity implements GUIInterface {
static private final int GO_FORWARD_MENU_DIALOG = 14;
static private final int FILE_MENU_DIALOG = 15;
static private final int NEW_GAME_DIALOG = 16;
static private final int CUSTOM1_BUTTON_DIALOG = 17;
static private final int CUSTOM2_BUTTON_DIALOG = 18;
@Override
protected Dialog onCreateDialog(int id) {
@ -1973,10 +2067,37 @@ public class DroidFish extends Activity implements GUIInterface {
AlertDialog alert = builder.create();
return alert;
}
case CUSTOM1_BUTTON_DIALOG:
return makeButtonDialog(custom1ButtonActions);
case CUSTOM2_BUTTON_DIALOG:
return makeButtonDialog(custom2ButtonActions);
}
return null;
}
private Dialog makeButtonDialog(ButtonActions buttonActions) {
List<CharSequence> names = new ArrayList<CharSequence>();
final List<UIAction> actions = new ArrayList<UIAction>();
HashSet<String> used = new HashSet<String>();
for (UIAction a : buttonActions.getMenuActions()) {
if ((a != null) && a.enabled() && !used.contains(a.getId())) {
names.add(getString(a.getName()));
actions.add(a);
used.add(a.getId());
}
}
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(buttonActions.getMenuTitle());
builder.setItems(names.toArray(new CharSequence[names.size()]), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
UIAction a = actions.get(item);
a.run();
}
});
return builder.create();
}
/** Open a load/save file dialog. Uses OI file manager if available. */
private void selectPgnFile(boolean save) {
String action = "org.openintents.action.PICK_FILE";

View File

@ -0,0 +1,34 @@
/*
DroidFish - An Android chess program.
Copyright (C) 2012 Peter Österlund, peterosterlund2@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.petero.droidfish;
/** Interface for user interface actions. */
public interface UIAction extends Runnable {
/** Get a unique identifier for this action. */
public String getId();
/** Get name resource for the action. */
public int getName();
/** Get icon resource or -1 for no icon. */
public int getIcon(boolean large);
/** Return true if the action is currently enabled. */
public boolean enabled();
}