new feature: long-click on wordlist button in BoardActivity brings up

a popup of all wordlists so you can browse one that's not in use,
e.g. to see if a word's legal in a larger wordlist.  Uses PopupMenu
class that was introduced in API 11, so 11's the target now and the
interface trick is used to prevent crashing on older devices (which
get a "needs newer Android" alert.)
This commit is contained in:
Eric House 2013-06-04 07:29:40 -07:00
parent c32df1a487
commit bb130a9b9f
7 changed files with 108 additions and 4 deletions

View file

@ -26,7 +26,7 @@
android:versionName="@string/app_version"
>
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="8" />
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="11" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

View file

@ -10,4 +10,4 @@
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-8
target=Google Inc.:Google APIs:11

View file

@ -94,6 +94,7 @@
<string name="key_notagain_trading">key_notagain_trading</string>
<string name="key_na_lookup">key_na_lookup</string>
<string name="key_na_browse">key_na_browse</string>
<string name="key_na_browseall">key_na_browseall</string>
<string name="key_na_values">key_na_values</string>
<string name="key_enable_debug">key_enable_debug</string>
<string name="key_download_path">key_download_path</string>

View file

@ -1860,6 +1860,9 @@
<string name="not_again_browse">This button opens the wordlist
browser on the current player\'s wordlist.</string>
<!-- -->
<string name="not_again_browseall">This button opens the wordlist
browser on the wordlist of your choice.</string>
<!-- -->
<string name="alert_empty_dictf">The wordlist %s contains only
tile information. There are no words to browse.</string>
@ -2149,7 +2152,7 @@
<string name="game_name_group_title">Name group</string>
<string name="cannot_delete_default_group">The group for new games
cannot be deleted."</string>
cannot be deleted.</string>
<string name="no_move_onegroup">Moving is impossible until there
is more than one group.</string>
@ -2164,4 +2167,7 @@
<string name="square_tiles_summary">Even if they can be taller</string>
<string name="change_groupf">Move game %s</string>
<string name="needs_newer">This feature requires a newer version
of Android.</string>
</resources>

View file

@ -102,6 +102,7 @@ public class BoardActivity extends XWActivity
private static final int BT_PICK_ACTION = 17;
private static final int SMS_PICK_ACTION = 18;
private static final int SMS_CONFIG_ACTION = 19;
private static final int BUTTON_BROWSEALL_ACTION = 20;
private static final String DLG_TITLE = "DLG_TITLE";
private static final String DLG_TITLESTR = "DLG_TITLESTR";
@ -890,6 +891,15 @@ public class BoardActivity extends XWActivity
String dictName = m_gi.dictName( m_view.getCurPlayer() );
DictBrowseActivity.launch( this, dictName );
break;
case BUTTON_BROWSEALL_ACTION:
View button = m_toolbar.getViewFor( Toolbar.BUTTON_BROWSE_DICT );
if ( !DictsActivity.handleDictsPopup( this, button ) ) {
// HACK: a static method can't easily call
// showOKOnlyDialog, so assume we know the reason
// for failure.
showOKOnlyDialog( R.string.needs_newer );
}
break;
case PREV_HINT_ACTION:
cmd = JNICmd.CMD_PREV_HINT;
break;
@ -1807,6 +1817,10 @@ public class BoardActivity extends XWActivity
R.string.not_again_browse,
R.string.key_na_browse,
BUTTON_BROWSE_ACTION );
m_toolbar.setLongClickListener( Toolbar.BUTTON_BROWSE_DICT,
R.string.not_again_browseall,
R.string.key_na_browseall,
BUTTON_BROWSEALL_ACTION );
m_toolbar.setListener( Toolbar.BUTTON_HINT_PREV,
R.string.not_again_hintprev,
R.string.key_notagain_hintprev,

View file

@ -36,6 +36,7 @@ import android.preference.PreferenceManager;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
@ -44,9 +45,12 @@ import android.widget.Button;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
import android.widget.ExpandableListView;
import android.widget.PopupMenu;
import android.widget.TextView;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import junit.framework.Assert;
import org.eehouse.android.xw4.DictUtils.DictAndLoc;
@ -59,6 +63,11 @@ public class DictsActivity extends XWExpandableListActivity
MountEventReceiver.SDCardNotifiee, DlgDelegate.DlgClickNotify,
DictImportActivity.DownloadFinishedListener {
private static interface SafePopup {
public void doPopup( Context context, View button );
}
private static SafePopup s_safePopup = null;
private static final String DICT_DOLAUNCH = "do_launch";
private static final String DICT_LANG_EXTRA = "use_lang";
private static final String DICT_NAME_EXTRA = "use_dict";
@ -76,6 +85,11 @@ public class DictsActivity extends XWExpandableListActivity
private static final int MOVE_DICT = DlgDelegate.DIALOG_LAST + 1;
private static final int SET_DEFAULT = DlgDelegate.DIALOG_LAST + 2;
private static final int DICT_OR_DECLINE = DlgDelegate.DIALOG_LAST + 3;
// I can't provide a subclass of MenuItem to hold DictAndLoc, so
// settle for a hash on the side.
private static HashMap<MenuItem, DictAndLoc> s_itemData;
private int m_lang = 0;
private String[] m_langs;
private String m_name = null;
@ -779,5 +793,48 @@ public class DictsActivity extends XWExpandableListActivity
}
}
private static class SafePopupImpl implements SafePopup {
public void doPopup( final Context context, View button ) {
MenuItem.OnMenuItemClickListener listener =
new MenuItem.OnMenuItemClickListener() {
public boolean onMenuItemClick( MenuItem item )
{
DictAndLoc dal = s_itemData.get( item );
s_itemData = null;
DictBrowseActivity.launch( context, dal.name, dal.loc );
return true;
}
};
s_itemData = new HashMap<MenuItem, DictAndLoc>();
PopupMenu popup = new PopupMenu( context, button );
Menu menu = popup.getMenu();
DictAndLoc[] dals = DictUtils.dictList( context );
for ( DictAndLoc dal : dals ) {
MenuItem item = menu.add( dal.name );
item.setOnMenuItemClickListener( listener );
s_itemData.put( item, dal );
}
popup.show();
}
}
public static boolean handleDictsPopup( Context context, View button )
{
if ( null == s_safePopup ) {
int sdkVersion = Integer.valueOf( android.os.Build.VERSION.SDK );
if ( 11 <= sdkVersion ) {
s_safePopup = new SafePopupImpl();
}
}
boolean canHandle = null != s_safePopup;
if ( canHandle ) {
s_safePopup.doPopup( context, button );
}
return canHandle;
}
}

View file

@ -92,15 +92,29 @@ public class Toolbar {
}
}
public void setListener( int index, View.OnClickListener listener )
public ImageButton getViewFor( int index )
{
TBButtonInfo info = s_buttonInfo[index];
ImageButton button = (ImageButton)m_activity.findViewById( info.m_id );
return button;
}
private void setListener( int index, View.OnClickListener listener )
{
ImageButton button = getViewFor( index );
if ( null != button ) {
button.setOnClickListener( listener );
}
}
private void setLongClickListener( int index, View.OnLongClickListener listener )
{
ImageButton button = getViewFor( index );
if ( null != button ) {
button.setOnLongClickListener( listener );
}
}
public void setListener( int index, final int msgID, final int prefsKey,
final int callback )
{
@ -112,6 +126,18 @@ public class Toolbar {
setListener( index, listener );
}
public void setLongClickListener( int index, final int msgID, final int prefsKey,
final int callback )
{
View.OnLongClickListener listener = new View.OnLongClickListener() {
public boolean onLongClick( View view ) {
m_activity.showNotAgainDlgThen( msgID, prefsKey, callback );
return true;
}
};
setLongClickListener( index, listener );
}
public void update( int index, boolean enable )
{
TBButtonInfo info = s_buttonInfo[index];